diff --git a/src/header/bits_open-flags/cbindgen.toml b/src/header/bits_open-flags/cbindgen.toml new file mode 100644 index 0000000000..06ef0dd6a0 --- /dev/null +++ b/src/header/bits_open-flags/cbindgen.toml @@ -0,0 +1,9 @@ +# Open flags are defined by fcntl.h: https://pubs.opengroup.org/onlinepubs/007904975/basedefs/fcntl.h.html +# And must be included in stdlib.h: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdlib.h.html +include_guard = "_RELIBC_BITS_OPEN_FLAGS_H" +language = "C" +no_includes = true +cpp_compat = true + +[enum] +prefix_with_name = true diff --git a/src/header/bits_open-flags/linux.rs b/src/header/bits_open-flags/linux.rs new file mode 100644 index 0000000000..e51a55a97c --- /dev/null +++ b/src/header/bits_open-flags/linux.rs @@ -0,0 +1,38 @@ +use crate::platform::types::c_int; + +/// Open for reading only. +pub const O_RDONLY: c_int = 0x0000; +/// Open for writing only. +pub const O_WRONLY: c_int = 0x0001; +/// Open for reading and writing. +pub const O_RDWR: c_int = 0x0002; +/// Mask for file access modes. +pub const O_ACCMODE: c_int = 0x0003; +/// Create file if it does not exist. +pub const O_CREAT: c_int = 0x0040; +/// Exclusive use flag. +pub const O_EXCL: c_int = 0x0080; +/// Do not assign controlling terminal. +pub const O_NOCTTY: c_int = 0x0100; +/// Truncate flag. +pub const O_TRUNC: c_int = 0x0200; +/// Set append mode. +pub const O_APPEND: c_int = 0x0400; +/// Non-blocking mode. +pub const O_NONBLOCK: c_int = 0x0800; +/// Fail if file is a non-directory file. +pub const O_DIRECTORY: c_int = 0x1_0000; +/// Do not follow symbolic links. +pub const O_NOFOLLOW: c_int = 0x2_0000; +/// Atomically set the `FD_CLOEXEC` flag on the new file desciptor. +pub const O_CLOEXEC: c_int = 0x8_0000; +/// Non-POSIX, see . +/// +/// Get a file descriptor to indicate a location in the filesystem tree and +/// to perform operations that act purely at the file descriptor level. +pub const O_PATH: c_int = 0x20_0000; + +/// Non-POSIX, see . +/// +/// Alternative name for `O_NONBLOCK`. +pub const O_NDELAY: c_int = O_NONBLOCK; diff --git a/src/header/bits_open-flags/mod.rs b/src/header/bits_open-flags/mod.rs new file mode 100644 index 0000000000..a1459bcc64 --- /dev/null +++ b/src/header/bits_open-flags/mod.rs @@ -0,0 +1,9 @@ +pub use self::sys::*; + +#[cfg(target_os = "linux")] +#[path = "linux.rs"] +pub mod sys; + +#[cfg(target_os = "redox")] +#[path = "redox.rs"] +pub mod sys; diff --git a/src/header/bits_open-flags/redox.rs b/src/header/bits_open-flags/redox.rs new file mode 100644 index 0000000000..c9768e494d --- /dev/null +++ b/src/header/bits_open-flags/redox.rs @@ -0,0 +1,53 @@ +use crate::platform::types::c_int; + +/// Open for reading only. +pub const O_RDONLY: c_int = 0x0001_0000; +/// Open for writing only. +pub const O_WRONLY: c_int = 0x0002_0000; +/// Open for reading and writing. +pub const O_RDWR: c_int = 0x0003_0000; +/// Mask for file access modes. +pub const O_ACCMODE: c_int = 0x0003_0000; +/// Non-blocking mode. +pub const O_NONBLOCK: c_int = 0x0004_0000; +/// Set append mode. +pub const O_APPEND: c_int = 0x0008_0000; +/// Non-POSIX, see . +/// +/// Atomically obtain a shared lock. +pub const O_SHLOCK: c_int = 0x0010_0000; +/// Non-POSIX, see . +/// +/// Atomically obtain an exclusive lock. +pub const O_EXLOCK: c_int = 0x0020_0000; +pub const O_ASYNC: c_int = 0x0040_0000; +pub const O_FSYNC: c_int = 0x0080_0000; +/// Write according to synchronized I/O file integrity completion. +pub const O_SYNC: c_int = O_FSYNC; +/// Atomically set the `FD_CLOEXEC` flag on the new file desciptor. +pub const O_CLOEXEC: c_int = 0x0100_0000; +/// Create file if it does not exist. +pub const O_CREAT: c_int = 0x0200_0000; +/// Truncate flag. +pub const O_TRUNC: c_int = 0x0400_0000; +/// Exclusive use flag. +pub const O_EXCL: c_int = 0x0800_0000; +/// Fail if file is a non-directory file. +pub const O_DIRECTORY: c_int = 0x1000_0000; +/// Non-POSIX, see . +/// +/// Get a file descriptor to indicate a location in the filesystem tree and +/// to perform operations that act purely at the file descriptor level. +pub const O_PATH: c_int = 0x2000_0000; +pub const O_SYMLINK: c_int = 0x4000_0000; +// Negative to allow it to be used as int +/// Do not follow symbolic links. +pub const O_NOFOLLOW: c_int = -0x8000_0000; + +/// Do not assign controlling terminal. +pub const O_NOCTTY: c_int = 0x00000200; + +/// Non-POSIX, see . +/// +/// Alternative name for `O_NONBLOCK`. +pub const O_NDELAY: c_int = O_NONBLOCK; diff --git a/src/header/fcntl/cbindgen.toml b/src/header/fcntl/cbindgen.toml index 912e56c8d6..dbcb3d1a38 100644 --- a/src/header/fcntl/cbindgen.toml +++ b/src/header/fcntl/cbindgen.toml @@ -18,6 +18,7 @@ include_guard = "_RELIBC_FCNTL_H" after_includes = """ #include // for pid_t from sys/types.h #include // for SEEK_CUR, SEEK_END and SEEK_SET from stdio.h +#include // for O_* constants, shared with stdlib.h """ language = "C" style = "Tag" diff --git a/src/header/fcntl/linux.rs b/src/header/fcntl/linux.rs index d6d44a50af..4dff8e23a2 100644 --- a/src/header/fcntl/linux.rs +++ b/src/header/fcntl/linux.rs @@ -1,46 +1,9 @@ use crate::platform::types::c_int; -/// Open for reading only. -pub const O_RDONLY: c_int = 0x0000; -/// Open for writing only. -pub const O_WRONLY: c_int = 0x0001; -/// Open for reading and writing. -pub const O_RDWR: c_int = 0x0002; -/// Mask for file access modes. -pub const O_ACCMODE: c_int = 0x0003; -/// Create file if it does not exist. -pub const O_CREAT: c_int = 0x0040; -/// Exclusive use flag. -pub const O_EXCL: c_int = 0x0080; -/// Do not assign controlling terminal. -pub const O_NOCTTY: c_int = 0x0100; -/// Truncate flag. -pub const O_TRUNC: c_int = 0x0200; -/// Set append mode. -pub const O_APPEND: c_int = 0x0400; -/// Non-blocking mode. -pub const O_NONBLOCK: c_int = 0x0800; -/// Fail if file is a non-directory file. -pub const O_DIRECTORY: c_int = 0x1_0000; -/// Do not follow symbolic links. -pub const O_NOFOLLOW: c_int = 0x2_0000; -/// Atomically set the `FD_CLOEXEC` flag on the new file desciptor. -pub const O_CLOEXEC: c_int = 0x8_0000; -/// Non-POSIX, see . -/// -/// Get a file descriptor to indicate a location in the filesystem tree and -/// to perform operations that act purely at the file descriptor level. -pub const O_PATH: c_int = 0x20_0000; - /// Close the file descriptor upon execution of an `exec` family function and /// in the new process image created by `posix_spawn()` or `posix_spawnp()`. pub const FD_CLOEXEC: c_int = 0x8_0000; -/// Non-POSIX, see . -/// -/// Alternative name for `O_NONBLOCK`. -pub const O_NDELAY: c_int = O_NONBLOCK; - // Flags for capability based "at" functions { /// Use the current working directory to determine the target of relative file /// paths. diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index 4dd77b3b36..1364f59e44 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -14,6 +14,7 @@ use crate::{ }; pub use self::sys::*; +pub use crate::header::bits_open_flags::*; use super::errno::EINVAL; diff --git a/src/header/fcntl/redox.rs b/src/header/fcntl/redox.rs index f09ef461df..f2cfcf1875 100644 --- a/src/header/fcntl/redox.rs +++ b/src/header/fcntl/redox.rs @@ -1,61 +1,9 @@ use crate::platform::types::c_int; -/// Open for reading only. -pub const O_RDONLY: c_int = 0x0001_0000; -/// Open for writing only. -pub const O_WRONLY: c_int = 0x0002_0000; -/// Open for reading and writing. -pub const O_RDWR: c_int = 0x0003_0000; -/// Mask for file access modes. -pub const O_ACCMODE: c_int = 0x0003_0000; -/// Non-blocking mode. -pub const O_NONBLOCK: c_int = 0x0004_0000; -/// Set append mode. -pub const O_APPEND: c_int = 0x0008_0000; -/// Non-POSIX, see . -/// -/// Atomically obtain a shared lock. -pub const O_SHLOCK: c_int = 0x0010_0000; -/// Non-POSIX, see . -/// -/// Atomically obtain an exclusive lock. -pub const O_EXLOCK: c_int = 0x0020_0000; -pub const O_ASYNC: c_int = 0x0040_0000; -pub const O_FSYNC: c_int = 0x0080_0000; -/// Write according to synchronized I/O file integrity completion. -pub const O_SYNC: c_int = O_FSYNC; -/// Atomically set the `FD_CLOEXEC` flag on the new file desciptor. -pub const O_CLOEXEC: c_int = 0x0100_0000; -/// Create file if it does not exist. -pub const O_CREAT: c_int = 0x0200_0000; -/// Truncate flag. -pub const O_TRUNC: c_int = 0x0400_0000; -/// Exclusive use flag. -pub const O_EXCL: c_int = 0x0800_0000; -/// Fail if file is a non-directory file. -pub const O_DIRECTORY: c_int = 0x1000_0000; -/// Non-POSIX, see . -/// -/// Get a file descriptor to indicate a location in the filesystem tree and -/// to perform operations that act purely at the file descriptor level. -pub const O_PATH: c_int = 0x2000_0000; -pub const O_SYMLINK: c_int = 0x4000_0000; -// Negative to allow it to be used as int -/// Do not follow symbolic links. -pub const O_NOFOLLOW: c_int = -0x8000_0000; - /// Close the file descriptor upon execution of an `exec` family function and /// in the new process image created by `posix_spawn()` or `posix_spawnp()`. pub const FD_CLOEXEC: c_int = 0x0100_0000; -/// Do not assign controlling terminal. -pub const O_NOCTTY: c_int = 0x00000200; - -/// Non-POSIX, see . -/// -/// Alternative name for `O_NONBLOCK`. -pub const O_NDELAY: c_int = O_NONBLOCK; - // Flags for capability based "at" functions { /// Use the current working directory to determine the target of relative file /// paths. diff --git a/src/header/mod.rs b/src/header/mod.rs index 890ebaa1af..006f5a6a87 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -30,6 +30,8 @@ pub mod bits_nlink_t; pub mod bits_null; #[path = "bits_off-t/mod.rs"] pub mod bits_off_t; +#[path = "bits_open-flags/mod.rs"] +pub mod bits_open_flags; #[path = "bits_pid-t/mod.rs"] pub mod bits_pid_t; pub mod bits_pthread; diff --git a/src/header/stdlib/cbindgen.toml b/src/header/stdlib/cbindgen.toml index 42614be7d7..7e8b9ec42d 100644 --- a/src/header/stdlib/cbindgen.toml +++ b/src/header/stdlib/cbindgen.toml @@ -12,8 +12,11 @@ # stdint.h needed for unintptr_t for __stack_chk_guard # sys/wait.h brings in signal.h which brings in features.h # features required for deprecated and no return annotations -sys_includes = ["stddef.h", "sys/wait.h", "fcntl.h", "stdint.h"] +sys_includes = ["stddef.h", "sys/wait.h", "stdint.h"] include_guard = "_RELIBC_STDLIB_H" +after_includes = """ +#include // for O_* constants, shared with fcntl.h +""" trailer = """ #ifndef _RELIBC_STDLIB_EXTRA_H #define _RELIBC_STDLIB_EXTRA_H