Skip to content
Snippets Groups Projects
Verified Commit 9c57c222 authored by jD91mZM2's avatar jD91mZM2
Browse files

Fix strcasecmp

parent daf65c7a
No related branches found
No related tags found
No related merge requests found
......@@ -109,10 +109,13 @@ pub unsafe extern "C" fn strcasecmp(mut first: *const c_char, mut second: *const
}
first = first.offset(1);
second = first.offset(1);
second = second.offset(1);
}
// Both strings ended at the same time too
(*first == *second) as c_int
// Both strings didn't end with NUL bytes
if *first != *second {
return -1;
}
0
}
#[no_mangle]
pub unsafe extern "C" fn strncasecmp(
......@@ -136,9 +139,12 @@ pub unsafe extern "C" fn strncasecmp(
}
first = first.offset(1);
second = first.offset(1);
second = second.offset(1);
n -= 1;
}
// Both strings ended at the same time too
(n == 0 || *first == *second) as c_int
// Both strings didn't end with NUL bytes (unless we reached the limit)
if n != 0 && *first != *second {
return -1;
}
0
}
sys_includes = ["stddef.h", "sys/types.h"]
sys_includes = ["stddef.h", "stdint.h", "sys/types.h"]
include_guard = "_SYS_SOCKET_H"
style = "Tag"
language = "C"
......
......@@ -11,8 +11,8 @@ int main() {
bcopy("hi", new, 3); // include nul byte
assert(!strcasecmp("hi", new));
assert(!strcasecmp("hi", "HI"));
assert(!strncasecmp("hi", "HIHI", 2));
assert(!strcasecmp("hello", "HEllO"));
assert(!strncasecmp("hello", "Hello World", 5));
bzero(new, 1);
assert(*new == 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment