diff options
Diffstat (limited to 'wcsmbs')
-rw-r--r-- | wcsmbs/Makefile | 2 | ||||
-rw-r--r-- | wcsmbs/test-wcsncmp.c | 2 | ||||
-rw-r--r-- | wcsmbs/wcsncmp.c | 36 |
3 files changed, 21 insertions, 19 deletions
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile index 69f78922a2..44a4494403 100644 --- a/wcsmbs/Makefile +++ b/wcsmbs/Makefile @@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \ isoc99_swscanf isoc99_vswscanf \ mbrtoc16 c16rtomb -strop-tests := wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy +strop-tests := wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \ tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \ tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests)) diff --git a/wcsmbs/test-wcsncmp.c b/wcsmbs/test-wcsncmp.c new file mode 100644 index 0000000000..07757d8e45 --- /dev/null +++ b/wcsmbs/test-wcsncmp.c @@ -0,0 +1,2 @@ +#define WIDE 1 +#include "../string/test-strncmp.c" diff --git a/wcsmbs/wcsncmp.c b/wcsmbs/wcsncmp.c index 59e003b857..e083ad8174 100644 --- a/wcsmbs/wcsncmp.c +++ b/wcsmbs/wcsncmp.c @@ -29,42 +29,42 @@ wcsncmp (s1, s2, n) const wchar_t *s2; size_t n; { - wint_t c1 = L'\0'; - wint_t c2 = L'\0'; + wchar_t c1 = L'\0'; + wchar_t c2 = L'\0'; if (n >= 4) { size_t n4 = n >> 2; do { - c1 = (wint_t) *s1++; - c2 = (wint_t) *s2++; + c1 = *s1++; + c2 = *s2++; if (c1 == L'\0' || c1 != c2) - return c1 - c2; - c1 = (wint_t) *s1++; - c2 = (wint_t) *s2++; + return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0); + c1 = *s1++; + c2 = *s2++; if (c1 == L'\0' || c1 != c2) - return c1 - c2; - c1 = (wint_t) *s1++; - c2 = (wint_t) *s2++; + return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0); + c1 = *s1++; + c2 = *s2++; if (c1 == L'\0' || c1 != c2) - return c1 - c2; - c1 = (wint_t) *s1++; - c2 = (wint_t) *s2++; + return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0); + c1 = *s1++; + c2 = *s2++; if (c1 == L'\0' || c1 != c2) - return c1 - c2; + return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0); } while (--n4 > 0); n &= 3; } while (n > 0) { - c1 = (wint_t) *s1++; - c2 = (wint_t) *s2++; + c1 = *s1++; + c2 = *s2++; if (c1 == L'\0' || c1 != c2) - return c1 - c2; + return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0); n--; } - return c1 - c2; + return 0; } |