diff --git a/include/stdint.h b/include/stdint.h index 989c7ca6fa..b22b3545b0 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -50,12 +50,7 @@ typedef __UINT8_TYPE__ u_int8_t; typedef __UINT16_TYPE__ uint16_t; typedef __UINT16_TYPE__ u_int16_t; #endif -#ifdef __UINT32_TYPE__ -typedef __UINT32_TYPE__ uint32_t; -typedef __UINT32_TYPE__ u_int32_t; -// Required by openlibm -typedef __UINT32_TYPE__ __uint32_t; -#endif +#include // for uint32_t #ifdef __UINT64_TYPE__ typedef __UINT64_TYPE__ uint64_t; typedef __UINT64_TYPE__ u_int64_t; diff --git a/src/header/bits_socklen-t/cbindgen.toml b/src/header/bits_socklen-t/cbindgen.toml index 1c90d7da48..affe1cb7e8 100644 --- a/src/header/bits_socklen-t/cbindgen.toml +++ b/src/header/bits_socklen-t/cbindgen.toml @@ -7,9 +7,9 @@ # - netdb.h # - sys/socket.h (where it should be defined) # -# TODO split out uint32_t to prevent including all of stdint.h -# stdint needed for uint32_t for socklen_t -sys_includes = ["stdint.h"] +# sys/socket.h spec states socklen_t must be at least 32bit wide. +# Application usage section recommends socklen_t value should not be larger than 2^31 -1. +sys_includes = ["bits/uint32-t.h"] include_guard = "_RELIBC_BITS_SOCKLEN_T_H" language = "C" no_includes = true diff --git a/src/header/bits_uint32-t/cbindgen.toml b/src/header/bits_uint32-t/cbindgen.toml new file mode 100644 index 0000000000..d176a7e077 --- /dev/null +++ b/src/header/bits_uint32-t/cbindgen.toml @@ -0,0 +1,19 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdint.h.html +# +# This type is split out to prevent importing all of stdint.h in other headers. +# +# socklen_t from sys/socket.h requires a 32bit integer even though the spec doesn't state uint32_t specifically +include_guard = "_RELIBC_BITS_UINT32_T_H" +after_includes = """ +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ uint32_t; +typedef __UINT32_TYPE__ u_int32_t; +// Required by openlibm +typedef __UINT32_TYPE__ __uint32_t; +#endif +""" +language = "C" +no_includes = true +cpp_compat = true +[enum] +prefix_with_name = true diff --git a/src/header/bits_uint32-t/mod.rs b/src/header/bits_uint32-t/mod.rs new file mode 100644 index 0000000000..3426ddd423 --- /dev/null +++ b/src/header/bits_uint32-t/mod.rs @@ -0,0 +1,5 @@ +//! `uint32_t` implementation for `stdint.h`. +//! +//! See . +//! +//! Implemented via typedef in cbindgen. diff --git a/src/header/mod.rs b/src/header/mod.rs index f06836cbed..55f6c1b039 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -62,6 +62,8 @@ pub mod bits_timeval; pub mod bits_ucred; #[path = "bits_uid-t/mod.rs"] pub mod bits_uid_t; +#[path = "bits_uint32-t/mod.rs"] +pub mod bits_uint32_t; #[path = "bits_useconds-t/mod.rs"] pub mod bits_useconds_t; pub mod bits_valist; diff --git a/src/header/sys_socket/cbindgen.toml b/src/header/sys_socket/cbindgen.toml index f941d31068..178ad9e184 100644 --- a/src/header/sys_socket/cbindgen.toml +++ b/src/header/sys_socket/cbindgen.toml @@ -5,10 +5,8 @@ # - "The header shall define the size_t and ssize_t types as described in ." # - "Inclusion of may also make visible all symbols from ." # -# TODO split out uint32_t from stdint.h in bits/socklen-t.h -# # bits/iovec.h brings in size_t -# bits/socklen_t brings in stdint.h for uint32_t for socklen_t +# bits/socklen_t brings in bits/uint32-t.h for uint32_t for socklen_t include_guard = "_RELIBC_SYS_SOCKET_H" after_includes = """ #include // for iovec from sys/uio.h