From 3603161a6f1f8fc800c282bd8a9befdf1e639367 Mon Sep 17 00:00:00 2001 From: auronandace Date: Thu, 4 Jun 2026 14:09:38 +0100 Subject: [PATCH] split out stdio constants for fcntl header --- src/header/bits_fcntl/cbindgen.toml | 7 +++++++ src/header/bits_fcntl/mod.rs | 8 ++++++++ src/header/fcntl/cbindgen.toml | 4 ++-- src/header/mod.rs | 1 + src/header/stdio/cbindgen.toml | 1 + src/header/stdio/constants.rs | 4 +--- src/header/stdio/mod.rs | 1 + src/header/unistd/cbindgen.toml | 4 +--- 8 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 src/header/bits_fcntl/cbindgen.toml create mode 100644 src/header/bits_fcntl/mod.rs diff --git a/src/header/bits_fcntl/cbindgen.toml b/src/header/bits_fcntl/cbindgen.toml new file mode 100644 index 0000000000..a7e0475f15 --- /dev/null +++ b/src/header/bits_fcntl/cbindgen.toml @@ -0,0 +1,7 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html +# +# These constants are split out to prevent including all of stdio.h into fcntl.h +include_guard = "_RELIBC_BITS_FCNTL_H" +language = "C" +no_includes = true +cpp_compat = true diff --git a/src/header/bits_fcntl/mod.rs b/src/header/bits_fcntl/mod.rs new file mode 100644 index 0000000000..9817d7b366 --- /dev/null +++ b/src/header/bits_fcntl/mod.rs @@ -0,0 +1,8 @@ +use crate::platform::types::c_int; + +/// Seek relative to start-of-file. +pub const SEEK_SET: c_int = 0; +/// Seek relative to current position. +pub const SEEK_CUR: c_int = 1; +/// Seek relative to end-of-file. +pub const SEEK_END: c_int = 2; diff --git a/src/header/fcntl/cbindgen.toml b/src/header/fcntl/cbindgen.toml index 41ac225301..fa5631ad21 100644 --- a/src/header/fcntl/cbindgen.toml +++ b/src/header/fcntl/cbindgen.toml @@ -10,12 +10,12 @@ # This approach was chosen because unistd.h requires parts of fcntl.h but not the other way around. # # stdarg.h brings in va_list for ... -# stdio.h brings in SEEK_SET, SEEK_CUR, and SEEK_END # sys/stat.h brings in mode_t, off_t and file mode constants -sys_includes = ["stdarg.h", "stdio.h", "sys/stat.h"] +sys_includes = ["stdarg.h", "sys/stat.h"] 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 """ language = "C" style = "Tag" diff --git a/src/header/mod.rs b/src/header/mod.rs index 49b8fec3a0..890ebaa1af 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -11,6 +11,7 @@ pub mod bits_clock_t; pub mod bits_clockid_t; #[path = "bits_dev-t/mod.rs"] pub mod bits_dev_t; +pub mod bits_fcntl; #[path = "bits_gid-t/mod.rs"] pub mod bits_gid_t; #[path = "bits_id-t/mod.rs"] diff --git a/src/header/stdio/cbindgen.toml b/src/header/stdio/cbindgen.toml index bd89ea3b36..af7d17ee11 100644 --- a/src/header/stdio/cbindgen.toml +++ b/src/header/stdio/cbindgen.toml @@ -3,6 +3,7 @@ sys_includes = ["stdarg.h", "stddef.h", "stdint.h", "features.h"] after_includes = """ #include // for off_t from sys/types.h #include // for ssize_t from sys/types.h +#include // for SEEK_CUR, SEEK_END and SEEK_SET """ include_guard = "_RELIBC_STDIO_H" trailer = """ diff --git a/src/header/stdio/constants.rs b/src/header/stdio/constants.rs index ff19da78e2..19fe69064e 100644 --- a/src/header/stdio/constants.rs +++ b/src/header/stdio/constants.rs @@ -16,9 +16,7 @@ pub const F_SVB: c_int = 64; pub const F_APP: c_int = 128; pub const F_BADJ: c_int = 256; -pub const SEEK_SET: c_int = 0; -pub const SEEK_CUR: c_int = 1; -pub const SEEK_END: c_int = 2; +/// SEEK_SET, SEEK_CUR and SEEK_END defined in fcntl bits header pub const _IOFBF: c_int = 0; pub const _IOLBF: c_int = 1; diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 44d5d3e6fb..93e717c827 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -39,6 +39,7 @@ use crate::{ use reader::Reader; pub use self::constants::*; +pub use crate::header::bits_fcntl::{SEEK_CUR, SEEK_END, SEEK_SET}; mod constants; pub use self::default::*; diff --git a/src/header/unistd/cbindgen.toml b/src/header/unistd/cbindgen.toml index 107420de87..a998d91c62 100644 --- a/src/header/unistd/cbindgen.toml +++ b/src/header/unistd/cbindgen.toml @@ -11,10 +11,8 @@ # Note that unistd.h may include fcntl.h and fcntl.h may include unistd.h thus creating a cycle. # Relibc decides that unistd.h will include fcntl.h and fcntl.h will not include unistd.h. # -# TODO fctnl.h shouldn't include all of stdio.h (split out some bits) -# # stddef.h brings in size_t and NULL -# fcntl.h brings in stdio.h bringing in SEEK_CUR, SEEK_END and SEEK_SET +# fcntl.h brings in bits/fcntl.h bringing in SEEK_CUR, SEEK_END and SEEK_SET # fcntl.h brings in sys/stat.h bringing in off_t, gid_t and uid_t # fcntl.h brings in pid_t # bits/useconds-t.h brings in features.h (for deprecated annotations)