@@ -26,24 +26,10 @@
size_t
__wcsnlen (const wchar_t *s, size_t maxlen)
{
- size_t len = 0;
-
- while (maxlen > 0 && s[len] != L'\0')
- {
- ++len;
- if (--maxlen == 0 || s[len] == L'\0')
- return len;
- ++len;
- if (--maxlen == 0 || s[len] == L'\0')
- return len;
- ++len;
- if (--maxlen == 0 || s[len] == L'\0')
- return len;
- ++len;
- --maxlen;
- }
-
- return len;
+ const wchar_t *ret = __wmemchr (s, L'\0', maxlen);
+ if (ret)
+ maxlen = ret - s;
+ return maxlen;
}
#ifndef WCSNLEN
weak_alias (__wcsnlen, wcsnlen)