Provide an implementation of strlen to be used as a fallback

This commit is contained in:
Vadim Petrochenkov 2022-03-18 18:18:28 +03:00
parent 1d52319c7c
commit 7f535824f5
2 changed files with 13 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#![cfg_attr(not(feature = "no-asm"), feature(global_asm))]
#![feature(cfg_target_has_atomic)]
#![feature(compiler_builtins)]
#![feature(core_ffi_c)]
#![feature(core_intrinsics)]
#![feature(lang_items)]
#![feature(linkage)]

View file

@ -68,6 +68,18 @@ intrinsics! {
pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
memcmp(s1, s2, n)
}
#[mem_builtin]
#[cfg_attr(not(all(target_os = "windows", target_env = "gnu")), linkage = "weak")]
pub unsafe extern "C" fn strlen(s: *const core::ffi::c_char) -> usize {
let mut n = 0;
let mut s = s;
while *s != 0 {
n += 1;
s = s.offset(1);
}
n
}
}
// `bytes` must be a multiple of `mem::size_of::<T>()`