Merge pull request #457 from petrochenkov/strlen

This commit is contained in:
Amanieu d'Antras 2022-03-18 21:11:23 +01:00 committed by GitHub
commit efe4e6aeb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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>()`