From 39f564ea230b2750b7ca257bf7dc1ca9d01405ba Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Mon, 3 Feb 2025 22:37:37 +0100 Subject: [PATCH 1/5] Add docs and deprecations for strings.h --- src/header/strings/mod.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 35377ff8a2..6b017fe456 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -1,4 +1,6 @@ -//! strings implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/strings.h.html +//! `strings.h` implementation. +//! +//! See . // TODO: set this for entire crate when possible #![deny(unsafe_op_in_unsafe_fn)] @@ -15,11 +17,23 @@ use crate::{ platform::types::*, }; +/// See . +/// +/// # Deprecation +/// The `bcmp()` function was marked legacy in the Open Group Base +/// Specifications Issue 6, and removed in Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn bcmp(first: *const c_void, second: *const c_void, n: size_t) -> c_int { unsafe { string::memcmp(first, second, n) } } +/// See . +/// +/// # Deprecation +/// The `bcopy()` function was marked legacy in the Open Group Base +/// Specifications Issue 6, and removed in Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn bcopy(src: *const c_void, dst: *mut c_void, n: size_t) { unsafe { @@ -27,6 +41,12 @@ pub unsafe extern "C" fn bcopy(src: *const c_void, dst: *mut c_void, n: size_t) } } +/// See . +/// +/// # Deprecation +/// The `bzero()` function was marked legacy in the Open Group Base +/// Specifications Issue 6, and removed in Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn bzero(dst: *mut c_void, n: size_t) { unsafe { @@ -34,6 +54,7 @@ pub unsafe extern "C" fn bzero(dst: *mut c_void, n: size_t) { } } +/// Non-POSIX, see . #[no_mangle] pub unsafe extern "C" fn explicit_bzero(s: *mut c_void, n: size_t) { for i in 0..n { @@ -46,6 +67,7 @@ pub unsafe extern "C" fn explicit_bzero(s: *mut c_void, n: size_t) { } } +/// See . #[no_mangle] pub extern "C" fn ffs(i: c_int) -> c_int { if i == 0 { @@ -54,16 +76,29 @@ pub extern "C" fn ffs(i: c_int) -> c_int { 1 + i.trailing_zeros() as c_int } +/// See . +/// +/// # Deprecation +/// The `index()` function was marked legacy in the Open Group Base +/// Specifications Issue 6, and removed in Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn index(s: *const c_char, c: c_int) -> *mut c_char { unsafe { string::strchr(s, c) } } +/// See . +/// +/// # Deprecation +/// The `rindex()` function was marked legacy in the Open Group Base +/// Specifications Issue 6, and removed in Issue 7. +#[deprecated] #[no_mangle] pub unsafe extern "C" fn rindex(s: *const c_char, c: c_int) -> *mut c_char { unsafe { string::strrchr(s, c) } } +/// See . #[no_mangle] pub unsafe extern "C" fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int { // SAFETY: the caller must ensure that s1 and s2 point to nul-terminated buffers. @@ -74,6 +109,7 @@ pub unsafe extern "C" fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_i inner_casecmp(zipped) } +/// See . #[no_mangle] pub unsafe extern "C" fn strncasecmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int { // SAFETY: the caller must ensure that s1 and s2 point to nul-terminated buffers. From 79badf4cfac66c800b9488bf27778315a2430f6b Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Mon, 3 Feb 2025 22:46:27 +0100 Subject: [PATCH 2/5] Add missing function stubs --- src/header/strings/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 6b017fe456..cb2475bafe 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -76,6 +76,18 @@ pub extern "C" fn ffs(i: c_int) -> c_int { 1 + i.trailing_zeros() as c_int } +/// See . +// #[no_mangle] +pub extern "C" fn ffsl(i: c_long) -> c_int { + unimplemented!(); +} + +/// See . +// #[no_mangle] +pub extern "C" fn ffsll(i: c_longlong) -> c_int { + unimplemented!(); +} + /// See . /// /// # Deprecation @@ -109,6 +121,13 @@ pub unsafe extern "C" fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_i inner_casecmp(zipped) } +// TODO: needs locale_t +// See . +// #[no_mangle] +/*pub extern "C" fn strcasecmp_l(s1: *const c_char, s2: *const c_char, locale: locale_t) -> c_int { + unimplemented!(); +}*/ + /// See . #[no_mangle] pub unsafe extern "C" fn strncasecmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int { @@ -120,6 +139,13 @@ pub unsafe extern "C" fn strncasecmp(s1: *const c_char, s2: *const c_char, n: si inner_casecmp(zipped) } +// TODO: needs locale_t +// See . +// #[no_mangle] +/*pub extern "C" fn strncasecmp_l(s1: *const c_char, s2: *const c_char, n: size_t, locale: locale_t) -> c_int { + unimplemented!(); +}*/ + /// Given two zipped `&c_char` iterators, either find the first comparison != 0, or return 0. fn inner_casecmp<'a>(iterator: impl Iterator) -> c_int { let mut cmp_iter = From 306196da2a8383919881f0eb997dc1756f7325e3 Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Mon, 3 Feb 2025 22:47:45 +0100 Subject: [PATCH 3/5] Implement ffsl(), ffsll() --- src/header/strings/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index cb2475bafe..2f4ab09513 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -79,13 +79,19 @@ pub extern "C" fn ffs(i: c_int) -> c_int { /// See . // #[no_mangle] pub extern "C" fn ffsl(i: c_long) -> c_int { - unimplemented!(); + if i == 0 { + return 0; + } + 1 + i.trailing_zeros() as c_int } /// See . // #[no_mangle] pub extern "C" fn ffsll(i: c_longlong) -> c_int { - unimplemented!(); + if i == 0 { + return 0; + } + 1 + i.trailing_zeros() as c_int } /// See . From 05eb0e85ded71b04e28e65e575dfc932667736ac Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Mon, 3 Feb 2025 23:07:02 +0100 Subject: [PATCH 4/5] Set #[no_mangle] on ffsl(), ffsll() --- src/header/strings/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 2f4ab09513..45981bc706 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -77,7 +77,7 @@ pub extern "C" fn ffs(i: c_int) -> c_int { } /// See . -// #[no_mangle] +#[no_mangle] pub extern "C" fn ffsl(i: c_long) -> c_int { if i == 0 { return 0; @@ -86,7 +86,7 @@ pub extern "C" fn ffsl(i: c_long) -> c_int { } /// See . -// #[no_mangle] +#[no_mangle] pub extern "C" fn ffsll(i: c_longlong) -> c_int { if i == 0 { return 0; From bda6a944b6f12e46bd9ea06c13c59b6fad4b6956 Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Tue, 4 Feb 2025 19:53:09 +0100 Subject: [PATCH 5/5] Fix error on deprecated functions --- src/header/strings/cbindgen.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header/strings/cbindgen.toml b/src/header/strings/cbindgen.toml index 2897bd5423..5f974357c2 100644 --- a/src/header/strings/cbindgen.toml +++ b/src/header/strings/cbindgen.toml @@ -1,4 +1,4 @@ -sys_includes = ["stddef.h", "stdint.h"] +sys_includes = ["features.h", "stddef.h", "stdint.h"] include_guard = "_RELIBC_STRINGS_H" language = "C" style = "Tag"