Fix wcschr(3) family like strchr(3) was fixed.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-09-24 21:35:55 +02:00
parent 86cd065aa7
commit 9291dae58f
3 changed files with 18 additions and 16 deletions

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -24,8 +24,8 @@
#include <wchar.h> #include <wchar.h>
extern "C" wchar_t* wcschr(const wchar_t* str, wchar_t c) extern "C" wchar_t* wcschr(const wchar_t* str, wchar_t uc)
{ {
wchar_t* ret = wcschrnul(str, c); wchar_t* ret = wcschrnul(str, uc);
return ret && c == ret[0] ? ret : NULL; return (wint_t) uc == ((wint_t*) ret)[0] ? ret : NULL;
} }

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -24,10 +24,10 @@
#include <wchar.h> #include <wchar.h>
extern "C" wchar_t* wcschrnul(const wchar_t* str, wchar_t c) extern "C" wchar_t* wcschrnul(const wchar_t* str, wchar_t uc)
{ {
for ( ; *str != c; str++ ) const wint_t* ustr = (const wint_t*) str;
if ( !*str ) for ( size_t i = 0; true; i++)
return NULL; if ( ustr[i] == (wint_t) uc || !ustr[i] )
return (wchar_t*) str; return (wchar_t*) str + i;
} }

View File

@ -1,6 +1,6 @@
/******************************************************************************* /*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library. This file is part of the Sortix C Library.
@ -24,14 +24,16 @@
#include <wchar.h> #include <wchar.h>
extern "C" wchar_t* wcsrchr(const wchar_t* str, wchar_t c) extern "C" wchar_t* wcsrchr(const wchar_t* str, wchar_t uc)
{ {
const wint_t* ustr = (const wint_t*) str;
const wchar_t* last = NULL; const wchar_t* last = NULL;
while ( *str ) for ( size_t i = 0; true; i++ )
{ {
if ( *str == c ) if ( ustr[i] == (wint_t) uc )
last = str; last = str + i;
str++; if ( !ustr[i] )
break;
} }
return (wchar_t*) last; return (wchar_t*) last;
} }