Skip to content
Snippets Groups Projects
Commit 40efea05 authored by Andrii Zymohliad's avatar Andrii Zymohliad
Browse files

Reimplement strpbrk() using strcspn()

parent 8d0308d3
Branches
Tags
1 merge request!75Implement strstr() and strpbrk() from string.h
......@@ -251,14 +251,12 @@ pub unsafe extern "C" fn strncpy(s1: *mut c_char, s2: *const c_char, n: usize) -
#[no_mangle]
pub unsafe extern "C" fn strpbrk(s1: *const c_char, s2: *const c_char) -> *mut c_char {
let mut i = 0;
while *s1.offset(i) != 0 {
if !strchr(s2, *s1.offset(i) as i32).is_null() {
return s1.offset(i) as *mut c_char;
}
i += 1;
let p = s1.offset(strcspn(s1, s2) as isize);
if *p != 0 {
p as *mut c_char
} else {
ptr::null_mut()
}
ptr::null_mut()
}
#[no_mangle]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment