Merge branch 'bits-open-flags' into 'master'

Move O_ constants to bits/open-flags.h for use by fcntl.h and stdlib.h

See merge request redox-os/relibc!1449
This commit is contained in:
Jeremy Soller
2026-06-10 08:56:04 -06:00
10 changed files with 117 additions and 90 deletions
+9
View File
@@ -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
+38
View File
@@ -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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// 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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// Alternative name for `O_NONBLOCK`.
pub const O_NDELAY: c_int = O_NONBLOCK;
+9
View File
@@ -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;
+53
View File
@@ -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 <https://man.openbsd.org/open.2>.
///
/// Atomically obtain a shared lock.
pub const O_SHLOCK: c_int = 0x0010_0000;
/// Non-POSIX, see <https://man.openbsd.org/open.2>.
///
/// 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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// 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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// Alternative name for `O_NONBLOCK`.
pub const O_NDELAY: c_int = O_NONBLOCK;
+1
View File
@@ -18,6 +18,7 @@ include_guard = "_RELIBC_FCNTL_H"
after_includes = """
#include <bits/pid-t.h> // for pid_t from sys/types.h
#include <bits/fcntl.h> // for SEEK_CUR, SEEK_END and SEEK_SET from stdio.h
#include <bits/open-flags.h> // for O_* constants, shared with stdlib.h
"""
language = "C"
style = "Tag"
-37
View File
@@ -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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// 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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// 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.
+1
View File
@@ -14,6 +14,7 @@ use crate::{
};
pub use self::sys::*;
pub use crate::header::bits_open_flags::*;
use super::errno::EINVAL;
-52
View File
@@ -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 <https://man.openbsd.org/open.2>.
///
/// Atomically obtain a shared lock.
pub const O_SHLOCK: c_int = 0x0010_0000;
/// Non-POSIX, see <https://man.openbsd.org/open.2>.
///
/// 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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// 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 <https://www.man7.org/linux/man-pages/man2/open.2.html>.
///
/// 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.
+2
View File
@@ -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;
+4 -1
View File
@@ -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 <bits/open-flags.h> // for O_* constants, shared with fcntl.h
"""
trailer = """
#ifndef _RELIBC_STDLIB_EXTRA_H
#define _RELIBC_STDLIB_EXTRA_H