diff --git a/include/stddef.h b/include/stddef.h deleted file mode 100644 index 7397dc006d..0000000000 --- a/include/stddef.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _STDDEF_H -#define _STDDEF_H - -// wchar_t should come before NULL and size_t -// according to comment in wchar cbindgen -#include -#include -#include - -#ifndef __PTRDIFF_TYPE__ -#define __PTRDIFF_TYPE__ long int -#endif -typedef __PTRDIFF_TYPE__ ptrdiff_t; - -typedef struct { long long __ll; long double __ld; } max_align_t; - -#define offsetof(type, member) __builtin_offsetof(type, member) - -#endif /* _STDDEF_H */ diff --git a/src/header/bits_null/cbindgen.toml b/src/header/bits_null/cbindgen.toml index f0f1e8a10e..16e065a090 100644 --- a/src/header/bits_null/cbindgen.toml +++ b/src/header/bits_null/cbindgen.toml @@ -10,6 +10,9 @@ include_guard = "_RELIBC_BITS_NULL_T_H" language = "C" no_includes = true after_includes = """ +// Null pointer constant. +// Any pointer object whose representation has all bits set to zero, perhaps by +// memset() to 0 or by calloc(), shall be treated as a null pointer. #ifdef __cplusplus #if __cplusplus >= 201103L #define NULL nullptr diff --git a/src/header/bits_null/mod.rs b/src/header/bits_null/mod.rs index aa36f0cf83..92f520a41e 100644 --- a/src/header/bits_null/mod.rs +++ b/src/header/bits_null/mod.rs @@ -1 +1,5 @@ -// NULL is defined in cbindgen +//! `NULL` from `stddef.h` implementation. +//! +//! See . +//! +//! Implemented via ifdefs and defines in cbindgen. diff --git a/src/header/bits_size-t/mod.rs b/src/header/bits_size-t/mod.rs index 6fefaa468d..4bde8f9acf 100644 --- a/src/header/bits_size-t/mod.rs +++ b/src/header/bits_size-t/mod.rs @@ -1,3 +1,7 @@ +//! `size_t` from `stddef.h` implementation. +//! +//! See . + use crate::platform::types::c_ulong; /// Unsigned integer type of the result of the sizeof operator. diff --git a/src/header/bits_wchar-t/cbindgen.toml b/src/header/bits_wchar-t/cbindgen.toml index 397c3fde12..1d25b19d39 100644 --- a/src/header/bits_wchar-t/cbindgen.toml +++ b/src/header/bits_wchar-t/cbindgen.toml @@ -3,6 +3,9 @@ # This type is split out to prevent importing all of stddef.h into inttypes.h include_guard = "_RELIBC_BITS_WCHAR_T_H" after_includes = """ +// Integer type whose range of values can represent distinct codes for all +// members of the largest extended character set specified among the supported +// locales; the null character shall have the code value zero. #ifndef _WCHAR_T #define _WCHAR_T #ifndef __cplusplus diff --git a/src/header/bits_wchar-t/mod.rs b/src/header/bits_wchar-t/mod.rs index 755d43c0cd..d299be4a82 100644 --- a/src/header/bits_wchar-t/mod.rs +++ b/src/header/bits_wchar-t/mod.rs @@ -1 +1,5 @@ -// `wchar_t` is defined in cbindgen +//! `wchar_t` from `stddef.h` implementation. +//! +//! See . +//! +//! Implemented via ifdefs and defines in cbindgen. diff --git a/src/header/mod.rs b/src/header/mod.rs index 08a8fdd610..5dbf59b857 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -136,7 +136,7 @@ pub mod spawn; pub mod stdarg; // stdatomic.h implemented in C // stdbool.h implemented in C -// stddef.h implemented in C +pub mod stddef; // stdint.h implemented in C pub mod stdio; pub mod stdlib; diff --git a/src/header/stddef/cbindgen.toml b/src/header/stddef/cbindgen.toml new file mode 100644 index 0000000000..ab10db8119 --- /dev/null +++ b/src/header/stddef/cbindgen.toml @@ -0,0 +1,29 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stddef.h.html +# +# There are no spec quotations relating to includes +include_guard = "_RELIBC_STDDEF_H" +after_includes = """ +// wchar_t should come before NULL and size_t +// according to comment in wchar cbindgen +#include +#include +#include + +#ifndef __PTRDIFF_TYPE__ +#define __PTRDIFF_TYPE__ long int +#endif +// Signed integer type of the result of subtracting two pointers. +typedef __PTRDIFF_TYPE__ ptrdiff_t; + +// Object type whose alignment is the greatest fundamental alignment. +typedef struct { long long __ll; long double __ld; } max_align_t; + +// Integer constant expression of type size_t, the value of which is the offset +// in bytes to the structure member from the beginning of its structure. +#define offsetof(type, member) __builtin_offsetof(type, member) +""" +language = "C" +no_includes = true +cpp_compat = true +[enum] +prefix_with_name = true diff --git a/src/header/stddef/mod.rs b/src/header/stddef/mod.rs new file mode 100644 index 0000000000..50fd1de6a0 --- /dev/null +++ b/src/header/stddef/mod.rs @@ -0,0 +1,5 @@ +//! `stddef.h` implementation. +//! +//! See . +//! +//! Implemented via includes, typedefs and defines in cbindgen.