diff --git a/libc/string/strcasecmp.cpp b/libc/string/strcasecmp.cpp index bfc3bda5..8fa76ed7 100644 --- a/libc/string/strcasecmp.cpp +++ b/libc/string/strcasecmp.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014. This file is part of the Sortix C Library. @@ -27,9 +27,10 @@ extern "C" int strcasecmp(const char* a, const char* b) { - while ( true ) + for ( size_t i = 0; true; i++ ) { - char ac = tolower(*a++), bc = tolower(*b++); + unsigned char ac = (unsigned char) tolower((unsigned char) a[i]); + unsigned char bc = (unsigned char) tolower((unsigned char) b[i]); if ( ac == '\0' && bc == '\0' ) return 0; if ( ac < bc ) diff --git a/libc/string/strcmp.cpp b/libc/string/strcmp.cpp index 6809a6a9..7b14353f 100644 --- a/libc/string/strcmp.cpp +++ b/libc/string/strcmp.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014. This file is part of the Sortix C Library. @@ -26,9 +26,10 @@ extern "C" int strcmp(const char* a, const char* b) { - while ( true ) + for ( size_t i = 0; true; i++ ) { - char ac = *a++, bc = *b++; + unsigned char ac = (unsigned char) a[i]; + unsigned char bc = (unsigned char) b[i]; if ( ac == '\0' && bc == '\0' ) return 0; if ( ac < bc ) diff --git a/libc/string/strncasecmp.cpp b/libc/string/strncasecmp.cpp index 265881b5..50674e4f 100644 --- a/libc/string/strncasecmp.cpp +++ b/libc/string/strncasecmp.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014. This file is part of the Sortix C Library. @@ -25,11 +25,12 @@ #include #include -extern "C" int strncasecmp(const char* a, const char* b, size_t maxcount) +extern "C" int strncasecmp(const char* a, const char* b, size_t max_count) { - while ( maxcount-- ) + for ( size_t i = 0; i < max_count; i++ ) { - char ac = tolower(*a++), bc = tolower(*b++); + unsigned char ac = (unsigned char) tolower((unsigned char) a[i]); + unsigned char bc = (unsigned char) tolower((unsigned char) b[i]); if ( ac == '\0' && bc == '\0' ) return 0; if ( ac < bc ) diff --git a/libc/string/strncmp.cpp b/libc/string/strncmp.cpp index 5e1020ff..429ee066 100644 --- a/libc/string/strncmp.cpp +++ b/libc/string/strncmp.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014. This file is part of the Sortix C Library. @@ -24,11 +24,12 @@ #include -extern "C" int strncmp(const char* a, const char* b, size_t maxcount) +extern "C" int strncmp(const char* a, const char* b, size_t max_count) { - while ( maxcount-- ) + for ( size_t i = 0; i < max_count; i++ ) { - char ac = *a++, bc = *b++; + unsigned char ac = (unsigned char) a[i]; + unsigned char bc = (unsigned char) b[i]; if ( ac == '\0' && bc == '\0' ) return 0; if ( ac < bc ) diff --git a/libc/wchar/wcscasecmp.cpp b/libc/wchar/wcscasecmp.cpp index ad354107..d55344d1 100644 --- a/libc/wchar/wcscasecmp.cpp +++ b/libc/wchar/wcscasecmp.cpp @@ -28,9 +28,10 @@ extern "C" int wcscasecmp(const wchar_t* a, const wchar_t* b) { - while ( true ) + for ( size_t i = 0; true; i++ ) { - wchar_t ac = towlower(*a++), bc = towlower(*b++); + wint_t ac = towlower((wint_t) a[i]); + wint_t bc = towlower((wint_t) b[i]); if ( ac == L'\0' && bc == L'\0' ) return 0; if ( ac < bc ) diff --git a/libc/wchar/wcscmp.cpp b/libc/wchar/wcscmp.cpp index ae0a02cf..9bd2d56d 100644 --- a/libc/wchar/wcscmp.cpp +++ b/libc/wchar/wcscmp.cpp @@ -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. @@ -26,9 +26,10 @@ extern "C" int wcscmp(const wchar_t* a, const wchar_t* b) { - while ( true ) + for ( size_t i = 0; true; i++ ) { - wchar_t ac = *a++, bc = *b++; + wint_t ac = (wint_t) a[i]; + wint_t bc = (wint_t) b[i]; if ( ac == L'\0' && bc == L'\0' ) return 0; if ( ac < bc ) diff --git a/libc/wchar/wcsncasecmp.cpp b/libc/wchar/wcsncasecmp.cpp index 8ac3ce07..24d27c25 100644 --- a/libc/wchar/wcsncasecmp.cpp +++ b/libc/wchar/wcsncasecmp.cpp @@ -26,11 +26,12 @@ #include extern "C" -int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t maxcount) +int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t max_count) { - while ( maxcount-- ) + for ( size_t i = 0; i < max_count; i++ ) { - wchar_t ac = towlower(*a++), bc = towlower(*b++); + wint_t ac = towlower((wint_t) a[i]); + wint_t bc = towlower((wint_t) b[i]); if ( ac == L'\0' && bc == L'\0' ) return 0; if ( ac < bc ) diff --git a/libc/wchar/wcsncmp.cpp b/libc/wchar/wcsncmp.cpp index 36100b20..a57a3720 100644 --- a/libc/wchar/wcsncmp.cpp +++ b/libc/wchar/wcsncmp.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. This file is part of the Sortix C Library. @@ -24,15 +24,17 @@ #include -extern "C" int wcsncmp(const wchar_t* a, const wchar_t* b, size_t n) +extern "C" int wcsncmp(const wchar_t* a, const wchar_t* b, size_t max_count) { - for ( size_t i = 0; i < n; i++ ) + for ( size_t i = 0; i < max_count; i++ ) { - if ( a[i] == L'\0' && b[i] == L'\0' ) + wint_t ac = (wint_t) a[i]; + wint_t bc = (wint_t) b[i]; + if ( ac == L'\0' && bc == L'\0' ) return 0; - if ( a[i] < b[i] ) + if ( ac < bc ) return -1; - if ( a[i] > b[i] ) + if ( ac > bc ) return 1; } return 0;