Merge branch 'wcscspn' into 'master'
Implements wcscspn function from wchar.h See merge request redox-os/relibc!196
This commit is contained in:
+13
-4
@@ -295,7 +295,7 @@ pub unsafe extern "C" fn wcscat(ws1: *mut wchar_t, ws2: *const wchar_t) -> *mut
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wcschr(ws: *const wchar_t, wc: wchar_t) -> *mut c_int {
|
||||
pub unsafe extern "C" fn wcschr(ws: *const wchar_t, wc: wchar_t) -> *mut wchar_t {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
if *ws.add(i) == wc {
|
||||
@@ -331,9 +331,18 @@ pub unsafe extern "C" fn wcscpy(ws1: *mut wchar_t, ws2: *const wchar_t) -> *mut
|
||||
}
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn wcscspn(ws1: *const wchar_t, ws2: *const wchar_t) -> size_t {
|
||||
unimplemented!();
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wcscspn(ws1: *const wchar_t, ws2: *const wchar_t) -> size_t {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
let wc = *ws1.add(i);
|
||||
|
||||
if wc == 0 || wcschr(ws2, wc) != 0 as *mut wchar_t {
|
||||
return i;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
|
||||
+2
-1
@@ -86,7 +86,8 @@ EXPECT_BINS=\
|
||||
wchar/mbrtowc \
|
||||
wchar/mbsrtowcs \
|
||||
wchar/putwchar \
|
||||
wchar/wcrtomb
|
||||
wchar/wcrtomb \
|
||||
wchar/wcscspn
|
||||
|
||||
# Binaries that may generate varied output
|
||||
BINS=\
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
assert(wcscspn(L"", L"") == 0);
|
||||
assert(wcscspn(L"", L"h") == 0);
|
||||
assert(wcscspn(L"a", L"a") == 0);
|
||||
|
||||
assert(wcscspn(L"ba", L"ab") == 0);
|
||||
assert(wcscspn(L"ba", L"a") == 1);
|
||||
|
||||
assert(wcscspn(L"abcdefghijkl$\"£$%", L"zxqrst,./$w") == 12);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user