strtok_r: return the end of s in lasts when finished and only reference musl

This commit is contained in:
Jeremy Soller
2026-01-12 14:56:40 -07:00
parent 5b0c8b361b
commit 5265b732cc
+3 -3
View File
@@ -607,7 +607,7 @@ pub unsafe extern "C" fn strtok_r(
delimiter: *const c_char,
lasts: *mut *mut c_char,
) -> *mut c_char {
// Loosely based on GLIBC implementation
// musl returns null if both s and lasts are null, it sets s to lasts otherwise
let mut haystack = s;
if haystack.is_null() {
if (*lasts).is_null() {
@@ -619,7 +619,7 @@ pub unsafe extern "C" fn strtok_r(
// Skip past any extra delimiter left over from previous call
haystack = haystack.add(strspn(haystack, delimiter));
if *haystack == 0 {
*lasts = ptr::null_mut();
*lasts = haystack;
return ptr::null_mut();
}
@@ -631,7 +631,7 @@ pub unsafe extern "C" fn strtok_r(
haystack = haystack.add(1);
*lasts = haystack;
} else {
*lasts = ptr::null_mut();
*lasts = token.add(strlen(token));
}
token