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" diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 35377ff8a2..45981bc706 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,47 @@ 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 { + 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 { + if i == 0 { + return 0; + } + 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 +127,14 @@ 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 { // SAFETY: the caller must ensure that s1 and s2 point to nul-terminated buffers. @@ -84,6 +145,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 =