diff --git a/include/stdarg.h b/include/stdarg.h deleted file mode 100644 index 28ff0905ba..0000000000 --- a/include/stdarg.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -typedef __builtin_va_list va_list; -#define va_start(v,l) __builtin_va_start(v,l) -#define va_end(v) __builtin_va_end(v) -#define va_arg(v,l) __builtin_va_arg(v,l) -#define va_copy(d,s) __builtin_va_copy(d,s) - -#endif /* _STDARG_H */ diff --git a/src/header/bits_valist/cbindgen.toml b/src/header/bits_valist/cbindgen.toml new file mode 100644 index 0000000000..95410a17a9 --- /dev/null +++ b/src/header/bits_valist/cbindgen.toml @@ -0,0 +1,18 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdarg.h.html +# +# This type is split out to prevent importing all of stdarg.h into other headers. +# +# POSIX headers that require va_list: +# - fcntl.h (not mentioned in spec but has ... in some functions) +# - stdarg.h (where it should be defined) +# - stdio.h +# - wchar.h (all of stdarg.h permitted) +include_guard = "_RELIBC_BITS_VALIST_T_H" +after_includes = """ +typedef __builtin_va_list va_list; +""" +language = "C" +no_includes = true +cpp_compat = true +[enum] +prefix_with_name = true diff --git a/src/header/bits_valist/mod.rs b/src/header/bits_valist/mod.rs new file mode 100644 index 0000000000..c1824f33bb --- /dev/null +++ b/src/header/bits_valist/mod.rs @@ -0,0 +1,5 @@ +//! `va_list` implementation for `stdarg.h`. +//! +//! See . +//! +//! Implemented via typedef forwarding to the C built-in in cbindgen. diff --git a/src/header/fcntl/cbindgen.toml b/src/header/fcntl/cbindgen.toml index dbcb3d1a38..9f50661efa 100644 --- a/src/header/fcntl/cbindgen.toml +++ b/src/header/fcntl/cbindgen.toml @@ -9,16 +9,15 @@ # To prevent a cycle between fcntl.h and unistd.h relibc only includes fcntl.h in unistd.h. # This approach was chosen because unistd.h requires parts of fcntl.h but not the other way around. # -# TODO split out va_list from stdarg.h -# -# stdarg.h brings in va_list for ... # sys/stat.h brings in mode_t, off_t and file mode constants -sys_includes = ["stdarg.h", "sys/stat.h"] +# spec does not mention va_list but some functions use ... which is effectively the same +sys_includes = ["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 +#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 +#include // for va_list from stdarg.h for ... """ language = "C" style = "Tag" diff --git a/src/header/mod.rs b/src/header/mod.rs index f21412269e..f89397d71e 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -62,6 +62,7 @@ pub mod bits_ucred; pub mod bits_uid_t; #[path = "bits_useconds-t/mod.rs"] pub mod bits_useconds_t; +pub mod bits_valist; #[path = "bits_wchar-t/mod.rs"] pub mod bits_wchar_t; pub mod bits_winsize; @@ -127,7 +128,7 @@ pub mod shadow; pub mod signal; // TODO: spawn.h // TODO: stdalign.h (likely C implementation) -// stdarg.h implemented in C +pub mod stdarg; // stdatomic.h implemented in C // stdbool.h implemented in C // stddef.h implemented in C diff --git a/src/header/stdarg/cbindgen.toml b/src/header/stdarg/cbindgen.toml new file mode 100644 index 0000000000..0a5252a2cc --- /dev/null +++ b/src/header/stdarg/cbindgen.toml @@ -0,0 +1,17 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdarg.h.html +# +# There are no spec quotations relating to includes +include_guard = "_RELIBC_STDARG_H" +after_includes = """ +#include // for va_list + +#define va_start(v,l) __builtin_va_start(v,l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v,l) __builtin_va_arg(v,l) +#define va_copy(d,s) __builtin_va_copy(d,s) +""" +language = "C" +no_includes = true +cpp_compat = true +[enum] +prefix_with_name = true diff --git a/src/header/stdarg/mod.rs b/src/header/stdarg/mod.rs new file mode 100644 index 0000000000..0067099323 --- /dev/null +++ b/src/header/stdarg/mod.rs @@ -0,0 +1,5 @@ +//! `stdarg.h` implementation. +//! +//! See . +//! +//! Implemented via defines forwarding to the C built-ins in cbindgen. diff --git a/src/header/stdio/cbindgen.toml b/src/header/stdio/cbindgen.toml index 6e6c497082..b74e8639d7 100644 --- a/src/header/stdio/cbindgen.toml +++ b/src/header/stdio/cbindgen.toml @@ -8,14 +8,14 @@ # - "The header shall define NULL as described in ." # - "Inclusion of the header may also make visible all symbols from ." # -# stdarg.h brings in va_list (TODO split out) # stddef.h brings in size_t and NULL # features.h required for deprecated annotations -sys_includes = ["stdarg.h", "stddef.h", "features.h"] +sys_includes = ["stddef.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 // for va_list from stdarg.h """ include_guard = "_RELIBC_STDIO_H" trailer = """ diff --git a/tests/wchar/wscanf.c b/tests/wchar/wscanf.c index 01962484f0..0dc4ebcfa0 100644 --- a/tests/wchar/wscanf.c +++ b/tests/wchar/wscanf.c @@ -1,10 +1,7 @@ /* swscanf example */ #include #include -// TODO: remove glibc? -#ifdef __GLIBC__ #include -#endif #include "test_helpers.h"