move stdarg header from C to cbindgen and create valist bits header

This commit is contained in:
auronandace
2026-06-16 11:35:40 +01:00
parent 038bae3cd6
commit 47b5f56d0b
8 changed files with 54 additions and 19 deletions
-10
View File
@@ -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 */
+18
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
//! `va_list` implementation for `stdarg.h`.
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdarg.h.html>.
//!
//! Implemented via typedef forwarding to the C built-in in cbindgen.
+5 -6
View File
@@ -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 <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/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
#include <bits/valist.h> // for va_list from stdarg.h for ...
"""
language = "C"
style = "Tag"
+2 -1
View File
@@ -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
+17
View File
@@ -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 <bits/valist.h> // 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
+5
View File
@@ -0,0 +1,5 @@
//! `stdarg.h` implementation.
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdarg.h.html>.
//!
//! Implemented via defines forwarding to the C built-ins in cbindgen.
+2 -2
View File
@@ -8,14 +8,14 @@
# - "The <stdio.h> header shall define NULL as described in <stddef.h>."
# - "Inclusion of the <stdio.h> header may also make visible all symbols from <stddef.h>."
#
# 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 <bits/off-t.h> // for off_t from sys/types.h
#include <bits/ssize-t.h> // for ssize_t from sys/types.h
#include <bits/fcntl.h> // for SEEK_CUR, SEEK_END and SEEK_SET
#include <bits/valist.h> // for va_list from stdarg.h
"""
include_guard = "_RELIBC_STDIO_H"
trailer = """