diff --git a/libc/Makefile b/libc/Makefile
index 3ae67cd5..1f60bcaf 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -139,6 +139,7 @@ wcslen.o \
wcsncat.o \
wcsncpy.o \
wcsrchr.o \
+wcsspn.o \
wctomb.o \
wctype.o \
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 1e241a49..bdb3f617 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -72,6 +72,7 @@ size_t wcslen(const wchar_t*);
wchar_t* wcsncat(wchar_t* restrict, const wchar_t* restrict, size_t);
wchar_t* wcsncpy(wchar_t* restrict, const wchar_t* restrict, size_t);
wchar_t* wcsrchr(const wchar_t*, wchar_t);
+size_t wcsspn(const wchar_t*, const wchar_t*);
/* TODO: These are not implemented in sortix libc yet. */
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
@@ -107,7 +108,6 @@ size_t mbsrtowcs(wchar_t* restrict, const char** restrict, size_t, mbstate_t* re
size_t wcscspn(const wchar_t*, const wchar_t*);
size_t wcsftime(wchar_t* restrict, size_t, const wchar_t* restrict, const struct tm* restrict);
size_t wcsrtombs(char* restrict, const wchar_t** restrict, size_t, mbstate_t* restrict);
-size_t wcsspn(const wchar_t*, const wchar_t*);
size_t wcsxfrm(wchar_t* restrict, const wchar_t* restrict, size_t);
unsigned long long wcstoull(const wchar_t* restrict, wchar_t** restrict, int);
unsigned long wcstoul(const wchar_t* restrict, wchar_t** restrict, int);
diff --git a/libc/wcsspn.cpp b/libc/wcsspn.cpp
new file mode 100644
index 00000000..a9414e90
--- /dev/null
+++ b/libc/wcsspn.cpp
@@ -0,0 +1,44 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ wcsspn.cpp
+ Search a string for a set of characters.
+
+*******************************************************************************/
+
+#include
+
+extern "C" size_t wcsspn(const wchar_t* str, const wchar_t* accept)
+{
+ size_t acceptlen = 0;
+ while ( accept[acceptlen] ) { acceptlen++; }
+ for ( size_t result = 0; true; result++ )
+ {
+ wchar_t c = str[result];
+ if ( !c ) { return result; }
+ bool matches = false;
+ for ( size_t i = 0; i < acceptlen; i++ )
+ {
+ if ( str[result] != accept[i] ) { continue; }
+ matches = true;
+ break;
+ }
+ if ( !matches ) { return result; }
+ }
+}