Merge pull request #457 from petrochenkov/strlen
This commit is contained in:
commit
efe4e6aeb5
2 changed files with 13 additions and 0 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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>()`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue