From cfe00d3316dc1a8135c861c741bf59a07292588d Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Fri, 8 Aug 2025 02:34:59 -0400 Subject: [PATCH] Add paths.h for Fish Fish only requires BSHELL. The constants are implementation specific so this header will evolve as needed. Cbindgen doesn't emit defines for strings (even CStrs) so I only provided what's needed for Fish in a C header for now with the ideal implementation, in Rust, unbuilt. --- include/paths.h | 6 ++++++ src/header/_paths/cbindgen.toml | 5 +++++ src/header/_paths/linux.rs | 29 +++++++++++++++++++++++++++++ src/header/_paths/mod.rs | 11 +++++++++++ src/header/_paths/redox.rs | 13 +++++++++++++ src/header/mod.rs | 2 ++ 6 files changed, 66 insertions(+) create mode 100644 include/paths.h create mode 100644 src/header/_paths/cbindgen.toml create mode 100644 src/header/_paths/linux.rs create mode 100644 src/header/_paths/mod.rs create mode 100644 src/header/_paths/redox.rs diff --git a/include/paths.h b/include/paths.h new file mode 100644 index 0000000000..8bbfa920c6 --- /dev/null +++ b/include/paths.h @@ -0,0 +1,6 @@ +#ifndef _RELIBC_PATHS_H +#define _RELIBC_PATHS_H + +#define _PATH_BSHELL "/bin/sh" + +#endif diff --git a/src/header/_paths/cbindgen.toml b/src/header/_paths/cbindgen.toml new file mode 100644 index 0000000000..885a98f571 --- /dev/null +++ b/src/header/_paths/cbindgen.toml @@ -0,0 +1,5 @@ +include_guard = "_RELIBC_PATHS_H" +language = "C" +style = "Type" +no_includes = true +cpp_compat = true diff --git a/src/header/_paths/linux.rs b/src/header/_paths/linux.rs new file mode 100644 index 0000000000..34cf290f7a --- /dev/null +++ b/src/header/_paths/linux.rs @@ -0,0 +1,29 @@ +//! Linux specific constants for paths.h. +//! Entirely borrowed from musl as there isn't a list of what to include. + +pub const _PATH_DEFPATH: &str = "/usr/local/bin:/bin:/usr/bin"; +pub const _PATH_STDPATH: &str = "/bin:/usr/bin:/sbin:/usr/sbin"; + +pub const _PATH_BSHELL: &str = "/bin/sh"; +pub const _PATH_CONSOLE: &str = "/dev/console"; +pub const _PATH_DEVNULL: &str = "/dev/null"; +pub const _PATH_KLOG: &str = "/proc/kmsg"; +pub const _PATH_LASTLOG: &str = "/var/log/lastlog"; +pub const _PATH_MAILDIR: &str = "/var/mail"; +pub const _PATH_MAN: &str = "/usr/share/man"; +pub const _PATH_MNTTAB: &str = "/etc/fstab"; +pub const _PATH_NOLOGIN: &str = "/etc/nologin"; +pub const _PATH_SENDMAIL: &str = "/usr/sbin/sendmail"; +pub const _PATH_SHADOW: &str = "/etc/shadow"; +pub const _PATH_SHELLS: &str = "/etc/shells"; +pub const _PATH_TTY: &str = "/dev/tty"; +pub const _PATH_UTMP: &str = "/var/run/utmp"; +pub const _PATH_WTMP: &str = "/var/log/wtmp"; +pub const _PATH_VI: &str = "/usr/bin/vi"; + +// Trailing backslash intentional as these are dir paths. +pub const _PATH_DEV: &str = "/dev/"; +pub const _PATH_TMP: &str = "/tmp/"; +pub const _PATH_VARDB: &str = "/var/lib/misc/"; +pub const _PATH_VARRUN: &str = "/var/run/"; +pub const _PATH_VARTMP: &str = "/var/tmp/"; diff --git a/src/header/_paths/mod.rs b/src/header/_paths/mod.rs new file mode 100644 index 0000000000..7c391b437c --- /dev/null +++ b/src/header/_paths/mod.rs @@ -0,0 +1,11 @@ +//! Implementation specific, non-standard path aliases + +#[cfg(target_os = "linux")] +#[path = "linux.rs"] +mod sys; + +#[cfg(target_os = "redox")] +#[path = "redox.rs"] +mod sys; + +pub use sys::*; diff --git a/src/header/_paths/redox.rs b/src/header/_paths/redox.rs new file mode 100644 index 0000000000..a2a0ed0274 --- /dev/null +++ b/src/header/_paths/redox.rs @@ -0,0 +1,13 @@ +//! Redox specific constants for paths.h. + +// NOTE: Cross check that new entries correspond to files on Redox before adding. + +pub const _PATH_BSHELL: &str = "/bin/sh"; +pub const _PATH_DEVNULL: &str = "/dev/null"; +pub const _PATH_MAN: &str = "/usr/share/man"; +pub const _PATH_TTY: &str = "/dev/tty"; + +// Trailing backslash intentional as these are dir paths. +pub const _PATH_DEV: &str = "/dev/"; +pub const _PATH_TMP: &str = "/tmp/"; +pub const _PATH_VARTMP: &str = "/var/tmp/"; diff --git a/src/header/mod.rs b/src/header/mod.rs index cbd1480738..4ad22103f3 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -47,6 +47,8 @@ pub mod netinet_in; pub mod netinet_ip; pub mod netinet_tcp; // TODO: nl_types.h +// TODO: Remove C header paths.h when cbindgen can export C/Rust strs +// pub mod paths; pub mod poll; pub mod pthread; pub mod pty;