From c4da23f1f5e6e7257bd6354860f2670329c50c16 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 24 Mar 2013 00:41:35 +0100 Subject: [PATCH] Add wcscmp(3). --- libc/Makefile | 1 + libc/include/wchar.h | 2 +- libc/wcscmp.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 libc/wcscmp.cpp diff --git a/libc/Makefile b/libc/Makefile index e8b7db71..a44a1419 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -133,6 +133,7 @@ wcrtomb.o \ wcscat.o \ wcschrnul.o \ wcschr.o \ +wcscmp.o \ wcscpy.o \ wcslen.o \ wctomb.o \ diff --git a/libc/include/wchar.h b/libc/include/wchar.h index faa6262b..a9c4e6d1 100644 --- a/libc/include/wchar.h +++ b/libc/include/wchar.h @@ -66,6 +66,7 @@ size_t mbrtowc(wchar_t* restrict, const char* restrict, size_t, mbstate_t* restr wchar_t* wcscat(wchar_t* restrict, const wchar_t* restrict); wchar_t* wcschr(const wchar_t*, wchar_t); wchar_t* wcschrnul(const wchar_t*, wchar_t); +int wcscmp(const wchar_t*, const wchar_t*); wchar_t* wcscpy(wchar_t* restrict, const wchar_t* restrict); size_t wcslen(const wchar_t*); @@ -87,7 +88,6 @@ int vswprintf(wchar_t* restrict, size_t, const wchar_t* restrict, va_list); int vswscanf(const wchar_t* restrict, const wchar_t* restrict, va_list); int vwprintf(const wchar_t* restrict, va_list); int vwscanf(const wchar_t* restrict, va_list); -int wcscmp(const wchar_t*, const wchar_t*); int wcscoll(const wchar_t*, const wchar_t*); int wcsncmp(const wchar_t*, const wchar_t*, size_t); int wcswidth(const wchar_t*, size_t); diff --git a/libc/wcscmp.cpp b/libc/wcscmp.cpp new file mode 100644 index 00000000..694f4866 --- /dev/null +++ b/libc/wcscmp.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + 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 . + + wcscmp.cpp + Compares two strings. + +*******************************************************************************/ + +#include + +extern "C" int wcscmp(const wchar_t* a, const wchar_t* b) +{ + while ( true ) + { + wchar_t ac = *a++, bc = *b++; + if ( ac == L'\0' && bc == L'\0' ) + return 0; + if ( ac < bc ) + return -1; + if ( ac > bc ) + return 1; + } +}