From b50262b76aa6b737c2f5775c810915fa401ddba1 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 27 Apr 2026 11:20:59 +0100 Subject: [PATCH] verify string header includes --- src/header/string/cbindgen.toml | 12 ++++++++++-- src/header/string/mod.rs | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/header/string/cbindgen.toml b/src/header/string/cbindgen.toml index e87cd7e152..f928e7282f 100644 --- a/src/header/string/cbindgen.toml +++ b/src/header/string/cbindgen.toml @@ -1,12 +1,20 @@ -sys_includes = ["stddef.h", "stdint.h", "strings.h"] +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/string.h.html +# +# Spec quotations relating to includes: +# - "The header shall define NULL and size_t as described in ." +# - "The header shall define the locale_t type as described in ." +# - "Inclusion of the header may also make visible all symbols from ." +sys_includes = ["stddef.h"] include_guard = "_RELIBC_STRING_H" after_includes = """ -#include // for locale_t +#include // for locale_t from locale.h """ language = "C" style = "Tag" no_includes = true cpp_compat = true +# make size_t actually size_t instead of uintptr_t (which would require stdint.h) +usize_is_size_t = true [enum] prefix_with_name = true diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs index 72f3b1452f..45621c2dcc 100644 --- a/src/header/string/mod.rs +++ b/src/header/string/mod.rs @@ -62,8 +62,8 @@ pub unsafe extern "C" fn memchr( /// See . #[unsafe(no_mangle)] -pub unsafe extern "C" fn memcmp(s1: *const c_void, s2: *const c_void, n: usize) -> c_int { - let (div, rem) = (n / mem::size_of::(), n % mem::size_of::()); +pub unsafe extern "C" fn memcmp(s1: *const c_void, s2: *const c_void, n: size_t) -> c_int { + let (div, rem) = (n / mem::size_of::(), n % mem::size_of::()); let mut a = s1.cast::(); let mut b = s2.cast::(); for _ in 0..div { @@ -405,6 +405,7 @@ pub unsafe extern "C" fn strlcat(dst: *mut c_char, src: *const c_char, dstsize: src_len + if dst_len > dstsize { dstsize } else { dst_len } } +/// Non-POSIX, see . #[unsafe(no_mangle)] pub unsafe extern "C" fn strsep(str_: *mut *mut c_char, sep: *const c_char) -> *mut c_char { let s = unsafe { *str_ };