From 6eaec56ef79c605e90664eb25f66c75ae8bd60c9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 14 Apr 2022 14:38:39 +0300 Subject: [PATCH] library: Remove definitions and reexports of `strlen` from libstd --- library/std/src/sys/hermit/mod.rs | 10 ---------- library/std/src/sys/sgx/mod.rs | 10 ---------- library/std/src/sys/solid/mod.rs | 2 -- library/std/src/sys/unix/mod.rs | 1 - library/std/src/sys/unsupported/common.rs | 16 ---------------- library/std/src/sys/windows/mod.rs | 1 - 6 files changed, 40 deletions(-) diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 08eca42380204..60b7a973cc2c1 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -71,16 +71,6 @@ pub fn unsupported_err() -> crate::io::Error { ) } -pub unsafe fn strlen(start: *const c_char) -> usize { - let mut str = start; - - while *str != 0 { - str = str.offset(1); - } - - (str as usize) - (start as usize) -} - #[no_mangle] pub extern "C" fn floor(x: f64) -> f64 { unsafe { intrinsics::floorf64(x) } diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs index 1333edb9881a1..696400670e04d 100644 --- a/library/std/src/sys/sgx/mod.rs +++ b/library/std/src/sys/sgx/mod.rs @@ -5,7 +5,6 @@ #![deny(unsafe_op_in_unsafe_fn)] use crate::io::ErrorKind; -use crate::os::raw::c_char; use crate::sync::atomic::{AtomicBool, Ordering}; pub mod abi; @@ -130,15 +129,6 @@ pub fn decode_error_kind(code: i32) -> ErrorKind { } } -pub unsafe fn strlen(mut s: *const c_char) -> usize { - let mut n = 0; - while unsafe { *s } != 0 { - n += 1; - s = unsafe { s.offset(1) }; - } - return n; -} - pub fn abort_internal() -> ! { abi::usercalls::exit(true) } diff --git a/library/std/src/sys/solid/mod.rs b/library/std/src/sys/solid/mod.rs index 492b1a55475a2..5ffa381f2e50f 100644 --- a/library/std/src/sys/solid/mod.rs +++ b/library/std/src/sys/solid/mod.rs @@ -99,5 +99,3 @@ pub fn hashmap_random_keys() -> (u64, u64) { (x1, x2) } } - -pub use libc::strlen; diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 3ad03a8868199..aedeb02e656d6 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -3,7 +3,6 @@ use crate::io::ErrorKind; pub use self::rand::hashmap_random_keys; -pub use libc::strlen; #[cfg(not(target_os = "espidf"))] #[macro_use] diff --git a/library/std/src/sys/unsupported/common.rs b/library/std/src/sys/unsupported/common.rs index 5274f53a7dbdb..4c9ade4a8c790 100644 --- a/library/std/src/sys/unsupported/common.rs +++ b/library/std/src/sys/unsupported/common.rs @@ -4,10 +4,6 @@ pub mod memchr { pub use core::slice::memchr::{memchr, memrchr}; } -// This is not necessarily correct. May want to consider making it part of the -// spec definition? -use crate::os::raw::c_char; - // SAFETY: must be called only once during runtime initialization. // NOTE: this is not guaranteed to run, for example when Rust code is called externally. pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} @@ -38,15 +34,3 @@ pub fn abort_internal() -> ! { pub fn hashmap_random_keys() -> (u64, u64) { (1, 2) } - -pub unsafe fn strlen(mut s: *const c_char) -> usize { - // SAFETY: The caller must guarantee `s` points to a valid 0-terminated string. - unsafe { - let mut n = 0; - while *s != 0 { - n += 1; - s = s.offset(1); - } - n - } -} diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 47917e57b19ed..31c7208bbf1ee 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -7,7 +7,6 @@ use crate::path::PathBuf; use crate::time::Duration; pub use self::rand::hashmap_random_keys; -pub use libc::strlen; #[macro_use] pub mod compat;