[tyndur-devel] [PATCH 3/3] libc: Ein paar wchar.h-Stringfunktionen
Antoine Kaufmann ·
+ libc: Ein paar Stringfunktionen in der wchar.h aus freebsd portiert + libc: Noch ein bisschen wctype.h damit die BSD-Funktionen kompilieren Signed-off-by: Antoine Kaufmann <toni at tyndur.org> --- src/include/wctype.h | 46 +++ src/modules/include/wchar.h | 422 +++++++++++++++++++++++++ src/modules/lib/stdlibc/wstring/wcpcpy.c | 55 ++++ src/modules/lib/stdlibc/wstring/wcpncpy.c | 60 ++++ src/modules/lib/stdlibc/wstring/wcscasecmp.c | 59 ++++ src/modules/lib/stdlibc/wstring/wcscat.c | 57 ++++ src/modules/lib/stdlibc/wstring/wcschr.c | 53 +++ src/modules/lib/stdlibc/wstring/wcscmp.c | 57 ++++ src/modules/lib/stdlibc/wstring/wcscoll.c | 37 +++ src/modules/lib/stdlibc/wstring/wcscpy.c | 55 ++++ src/modules/lib/stdlibc/wstring/wcscspn.c | 64 ++++ src/modules/lib/stdlibc/wstring/wcsdup.c | 52 +++ src/modules/lib/stdlibc/wstring/wcslcat.c | 74 +++++ src/modules/lib/stdlibc/wstring/wcslcpy.c | 72 +++++ src/modules/lib/stdlibc/wstring/wcslen.c | 53 +++ src/modules/lib/stdlibc/wstring/wcsncasecmp.c | 70 ++++ src/modules/lib/stdlibc/wstring/wcsncat.c | 68 ++++ src/modules/lib/stdlibc/wstring/wcsncmp.c | 67 ++++ src/modules/lib/stdlibc/wstring/wcsncpy.c | 70 ++++ src/modules/lib/stdlibc/wstring/wcsnlen.c | 53 +++ src/modules/lib/stdlibc/wstring/wcspbrk.c | 64 ++++ src/modules/lib/stdlibc/wstring/wcsrchr.c | 60 ++++ src/modules/lib/stdlibc/wstring/wcsspn.c | 67 ++++ src/modules/lib/stdlibc/wstring/wcsstr.c | 66 ++++ src/modules/lib/stdlibc/wstring/wcstok.c | 108 +++++++ src/modules/lib/stdlibc/wstring/wmemchr.c | 59 ++++ src/modules/lib/stdlibc/wstring/wmemcmp.c | 62 ++++ src/modules/lib/stdlibc/wstring/wmemcpy.c | 50 +++ src/modules/lib/stdlibc/wstring/wmemmove.c | 49 +++ src/modules/lib/stdlibc/wstring/wmemset.c | 56 ++++ 30 files changed, 2185 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/stdlibc/wstring/wcpcpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcpncpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscasecmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscat.c create mode 100644 src/modules/lib/stdlibc/wstring/wcschr.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscoll.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcscspn.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsdup.c create mode 100644 src/modules/lib/stdlibc/wstring/wcslcat.c create mode 100644 src/modules/lib/stdlibc/wstring/wcslcpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcslen.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncasecmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncat.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsncpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsnlen.c create mode 100644 src/modules/lib/stdlibc/wstring/wcspbrk.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsrchr.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsspn.c create mode 100644 src/modules/lib/stdlibc/wstring/wcsstr.c create mode 100644 src/modules/lib/stdlibc/wstring/wcstok.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemchr.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemcmp.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemcpy.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemmove.c create mode 100644 src/modules/lib/stdlibc/wstring/wmemset.c diff --git a/src/include/wctype.h b/src/include/wctype.h index e69de29..8f21b94 100644 --- a/src/include/wctype.h +++ b/src/include/wctype.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_H_ +#define _WCTYPE_H_ + +#define iswupper(c) ((c) >= L'A' && (c) <= L'Z') +#define iswlower(c) ((c) >= L'a' && (c) <= L'z') + +static inline wint_t towlower(wint_t c) +{ + return iswupper(c) ? c + (L'a' - L'A') : c; +} + +static inline wint_t towupper(wint_t c) +{ + return iswlower(c) ? c - (L'a' - L'A') : c; +} + +#endif /* ndef WCTYPE_H */ + diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h index 6ed1d51..d664741 100644 --- a/src/modules/include/wchar.h +++ b/src/modules/include/wchar.h @@ -87,6 +87,428 @@ int wcwidth(wchar_t wc); int wcswidth(const wchar_t* wcs, size_t len); +/** + * Einen String aus breiten Zeichen kopieren, das ist das Pendant zu stpcpy. Die + * beiden Strings duerfen sich nicht ueberlappen. Das abschliessende L'0' wird + * mitkopiert. + * + * @see stpcpy + * @see wcscpy + * @see wcpncpy + * @param dst Zeiger auf die Speicherstelle in die der Kopiertestring abgelegt + * werden soll. Dabei muss vom Aufrufer sichergestellt werden, dass + * dort mindestens speicher fuer wcslen(src) + 1 breite Zeichen ist. + * @param src + * + * @return Zeiger auf das Ende (L'0') des Zielstrings. + */ +wchar_t* wcpcpy(wchar_t* dst, const wchar_t* src); + +/** + * String aus breiten Zeichen kopieren. Dabei werden hoechstens len Zeichen + * kopiert. Sind in src weniger als len Zeichen wird dst mit L'\0' aufgefuellt. + * Ist src laenger als oder gleich lang wie len wird der String in dst nich + * nullterminiert, der Rueckgabewert zeigt also nich auf ein L'\0'. Die beiden + * Speicherbereiche duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcpncpy + * @param dst Zeiger auf den Speicherbereich der len breite Zeichen aufnehmen + * kann. Es werden genau len Zeichen hineingeschrieben. + * @param src Quellstring + * @param len Anzahl der Zeichen, die in dst geschrieben werden sollen. + * + * @return Zeiger auf das letzte geschriebene Byte, also immer dst + len - 1 + */ +wchar_t* wcpncpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen inklusive abschliessendes L'\0'. Diese + * Funktion ist das Pendant zu strcasecmp. + * + * @see strcasecmp + * @see wcscmp + * @see towlower + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscasecmp(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei wird der Inhalt von + * src inklusive dem abschliessenden L'\0' ans Ende von dst kopiert. Der + * Aufrufer muss sicherstellen, dass nach dst genug Speicher frei ist. Diese + * Funktion ist das Pendant zu strcat. + * + * @see strcat + * @see wcsncat + * @param dst Zeiger auf den String an dessen Ende src angehaengt werden soll. + * @param src Zeiger auf den String der an dst angehaengt werden soll. + * + * @return dst + */ +wchar_t* wcscat(wchar_t* dst, const wchar_t* src); + +/** + * Erstes Vorkommen eines breiten Zeichens aus einem String aus breiten Zeichen + * heraussuchen. Diese Funktion ist das Pendant zu strchr. + * + * @see strchr + * @param wcs Zeiger auf den String in dem gesucht werden soll. + * @param wc Zeichen das gesucht werden soll. + * + * @return Zeiger auf das erste gefundene Zeichen oder NULL wenn keines gefunden + * wurde. + */ +wchar_t* wcschr(const wchar_t* wcs, wchar_t wc); + +/** + * Zwei Strings aus breiten Zeichen inklusive dem abschliessenden L'\0' + * vergleichen. Diese Funktion ist das Pendant zu strcmp. + * + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscmp(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * TODO + */ +int wcscoll(const wchar_t* wcs1, const wchar_t* wcs2); + +/** + * String aus Breiten Zeichen inklusive abschliessendem L'\0' kopieren. Der + * Aufrufer hat sicherzustellen, dass dst genug Platz bietet. Die beiden Strings + * duerfen sich nicht uberlappen. Diese Funktion ist das Pendant zu strcpy. + * + * @see strcpy + * @see wcsncpy + * @see wcpcpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den String der kopiert werden soll. + * + * @return dst + */ +wchar_t* wcscpy(wchar_t* dst, const wchar_t* src); + +/** + * String aus breiten Zeichen nach einem Vorkommen eines Zeichens aus set + * durchsuchen. Diese Funktion ist das Pendant zu strcspn. + * + * @see strcspn + * @see wcsspn + * @param wcs Zeiger auf den String, dar durchsucht werden soll + * @param set Zeiger auf den String mit den zu suchenden Zeichen. + * + * @return Offset vom Anfang des Strings oder wcslen(wcs) wenn kein Vorkommen + * gefunden wurde. + */ +size_t wcscspn(const wchar_t* wcs, const wchar_t* set); + +/** + * String aus breiten Zeichen in einen neu allozierten Speicherbereich kopieren. + * Diese Funktion ist das Pendant zu strdup. + * + * @see strdup + * @param wcs Zeiger auf den zu kopierenden String + * + * @return Zeiger auf die Kopie. Muss vom Aufrufer freigegeben werden. Im + * Fehlerfall NULL. + */ +wchar_t* wcsdup(const wchar_t* wcs); + +/** + * Kopiert src an das Ende des Strings dst. Dabei wird der String dst auf + * maximal len - 1 Zeichen und L'\0' verlaengert, ausser wenn len == 0. + * + * @see wcsncat + * @param dst Zeiger auf String an den src angehaengt werden soll + * @param src Zeiger auf String der an dst angehaengt werden soll + * @param len Anzahl Zeichen auf die dst Maximal verlaengert werden darf + * inklusiv L'\0.' + * + * @return wcslen(urspruengliches dst) + wcslen(src); Wenn der Rueckgabewert >= + * len ist, wurde src nich vollstaendig kopiert. + */ +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Kopiert einen String aus breiten Zeichen. Dabei werden maximal len - 1 + * Zeichen kopiert, und dst wird immer mit L'\0' terminiert, wenn len != 0 ist. + * + * @see wcscpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den Quellstring + * @param len Anzahl der Zeichen inklusiv abschliessendes L'\0', die maximal in + * dst geschrieben werden sollen. + * + * @return wcslen(src); Wenn der Rueckgabewert <= len ist, wurde src nicht + * vollstaendig kopiert. + */ +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Laenge eines Strings aus breiten Zeichen bestimmen. Dabei werden die Zeichen + * gezaehlt, bis ein abschliessendes L'\0' gefunden wird. Das L'\0' wird nicht + * mitgezaehlt. Diese Funktion ist das Pendant zu strlen. + * + * @see strlen + * @param wcs Zeiger auf den String + * + * @return Laenge des Strings in Zeichen + */ +size_t wcslen(const wchar_t* wcs); + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen. Dabei werden maximal die ersten len + * Zeichen von Beiden Strings verglichen. Diese Funktion ist das Pendant zu + * strncasecmp. + * + * @see strncasecmp + * @see wcscasecmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein L'\0' gefunden wird. + * + * @return 0 wenn die beiden Strings gleich sind, < 0 wenn das Zeichen in wcs2 + * groesser ist als das in wcs1 und > 0 wenn das Zeichen in wcs1 + * groesser ist als das in wcs2. + */ +int wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei werden maximal len + * Zeichen aus src kopiert. Der Aufrufer muss sicherstellen, dass nach dem + * String, auf den dst zeigt, noch mindestens len + 1 Zeichen platz haben. dst + * wird in jedem Fall mit L'\0' terminiert. Diese Funktion ist das Pendant zu + * strncat. + * + * @see strncat + * @see wcscat + * @param dst String an den src angehaengt werden soll + * @param src String der an dst angehaengt werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden aus src + * + * @return dst + */ +wchar_t* wcsncat(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Zwei Strings aus breiten Zeichen vergleichen. Dabei werden maximal len + * Zeichen verglichen. Diese Funktion ist das Pendant zu strncmp. + * + * @see strncmp + * @see wcscmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein abschliessendes L'\0' angetroffen wurde. + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcsncmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * String aus breiten Zeichen kopieren. Dabei werden maximal len Zeichen + * kopiert. Die restlichen Zeichen im Puffer werden mit L'\0' gefuellt. Ist src + * gleich lang wie oder laenger als len, wird dst nicht mit L'\0' terminiert. + * Die beiden Strings duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcscpy + * @param src String der kopiert werden soll + * @param dst Zeiger auf den Speicherbereich in den src kopiert werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden sollen + * + * @return dst + */ +wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Laenge eines Strings aus breiten Zeichen errechnen. Dabei werden maximal max + * Zeichen gezaehlt. Diese Funktion ist das Pendant zu strnlen. + * + * @see strnlen + * @see wcslen + * @param wcs String + * @param max Anzahl der Zeichen, die maximal gezaehlt werden sollen + * + * @return Anzahl der Zeichen ohne abschliessendes L'\0' + */ +size_t wcsnlen(const wchar_t* wcs, size_t max); + +/** + * Erstes vorkommen eines breiten Zeichens aus set im String aus breiten Zeichen + * wcs suchen. Diese Funktion ist das Pendant zu strpbrk. + * + * @see strpbrk + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set String aus Zeichen nach denen gesucht werden soll + * + * @return Zeiger auf die Position an der ein Zeichen gefunden wurde oder NULL + * falls keines gefunden wurde. + */ +wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* set); + +/** + * Letztes Vorkommen eines breiten Zeichens in einem String aus breiten Zeichen + * suchen. Diese Funktion ist das Pendant zu strrchr. + * + * @see strrchr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param wc Zeichen das gesucht werden soll + * + * @return Zeiger auf das letzte gefundene Vorkommen, oder NULL falls das + * Zeichen nicht gefunden wurde. + */ +wchar_t* wcsrchr(const wchar_t* wcs, wchar_t wc); + +/** + * Durchsucht einen String aus breiten Zeichen nach dem ersten Zeichen das nicht + * in set vorkommt. Diese Funktion ist das Pendant zu strspn. + * + * @see strspn + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set Zeichen die zugelassen sind + * + * @return Offset des ersten Zeichens das nicht in set vorkommt, oder + * wcslen(wcs) falls alle Zeichen in set enthalten sind. + */ +size_t wcsspn(const wchar_t* wcs, const wchar_t* set); + +/** + * Erstes Vorkommen des Breiten Strings find in wcs suchen. Diese Funktion ist + * das Pendant zu strstr. + * + * @see strstr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param find String der gesucht werden soll + * + * @return Zeiger auf das erste Vorkommen in wcs oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wcsstr(const wchar_t* wcs, const wchar_t* find); + +/** + * String aus breiten Zeichen in Tokens aufspalten, die durch die in delim + * angegebenen Zeichen getrennt werden. wcs wird dabei veraendert. Ist wcs != + * NULL beginnt die suche dort, sonst wird bei *last begonnen. *last wird + * jeweils auf den Anfang des naechsten Token gesetzt, oder auf NULL, wenn das + * Ende erreicht wurde. + * Diese Funktion ist das Pendant zu strtok. + * + * @see strtok + * @param wcs Zeiger auf das Zeichen bei dem die Zerlegung in Tokens begonnen + * werden soll, oder NULL, wenn der Wert von *last genommen werden + * soll. + * @param delim Zeichen die zwei Tokens voneinander trennen koennen + * @param last Zeiger auf die Speicherstelle an der die Funktion die Position + * des naechsten token speichern kann fuer den internen Gebrauch, + * um beim Naechsten Aufruf mit wcs == NULL das naechste Token + * zurueck geben zu koennen. + * + * @return Zeiger auf das aktuelle Token, oder NULL wenn keine Tokens mehr + * vorhanden sind. + */ +wchar_t* wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** last); + +/** + * Speicherbereich aus breiten Zeichen nach einem bestimmten Zeichen + * durchsuchen. Diese Funktion ist das Pendant zu memchr. + * + * @see memchr + * @see wcschr + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zu suchendes Zeichen + * @param len Laenge des Speicherbereichs + * + * @return Zeiger auf das gefundene Zeichen oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wmemchr(const wchar_t* wcs, wchar_t wc, size_t len); + +/** + * Zwei Speicherbereiche aus breiten Zeichen vergleichen. Diese Funktion ist das + * Pendant zu memcmp. + * + * @see memcmp + * @see wcscpm + * @see wcsncmp + * @param wcs1 Zeiger auf den ersten Speicherbereich + * @param wcs2 Zeiger auf den zweiten Speicherbereich + * @param len Laenge der beiden Speicherbereiche + * + * @return 0 wenn die beiden Speicherbereiche gleich sind, < 0 wenn das erste + * unterschiedliche Zeichen in wcs1 kleiner ist als das + * Korrespondierende in wcs2 oder > 0 wenn es groesser ist. + */ +int wmemcmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len); + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich nicht ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memcpy + * @see wcsncpy + * @see wcscpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemcpy(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memmove + * @see wmemcpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t len); + +/** + * Speicherbereich aus breiten Zeichen mit einem bestimmten Zeichen ausfuellen. + * Diese Funktion ist das pendant zu memset. + * + * @see memset + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zeichen mit dem der Speicherbereich gefuellt werden soll + * @param len Laenge des Speicherbereichs + * + * @return wcs + */ +wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t len); + + + /* WSTDIO */ diff --git a/src/modules/lib/stdlibc/wstring/wcpcpy.c b/src/modules/lib/stdlibc/wstring/wcpcpy.c new file mode 100644 index 0000000..5d71596 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcpcpy.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1999 + * David E. O'Brien + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + +/** + * Einen String aus breiten Zeichen kopieren, das ist das Pendant zu stpcpy. Die + * beiden Strings duerfen sich nicht ueberlappen. Das abschliessende L'0' wird + * mitkopiert. + * + * @see stpcpy + * @see wcscpy + * @see wcpncpy + * @param dst Zeiger auf die Speicherstelle in die der Kopiertestring abgelegt + * werden soll. Dabei muss vom Aufrufer sichergestellt werden, dass + * dort mindestens speicher fuer wcslen(src) + 1 breite Zeichen ist. + * @param src + * + * @return Zeiger auf das Ende (L'0') des Zielstrings. + */ +wchar_t* wcpcpy(wchar_t* dst, const wchar_t* src) +{ + for (; (*dst = *src); ++src, ++dst) { } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcpncpy.c b/src/modules/lib/stdlibc/wstring/wcpncpy.c new file mode 100644 index 0000000..b04be05 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcpncpy.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2009 David Schultz <das at FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + +/** + * String aus breiten Zeichen kopieren. Dabei werden hoechstens len Zeichen + * kopiert. Sind in src weniger als len Zeichen wird dst mit L'\0' aufgefuellt. + * Ist src laenger als oder gleich lang wie len wird der String in dst nich + * nullterminiert, der Rueckgabewert zeigt also nich auf ein L'\0'. Die beiden + * Speicherbereiche duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcpncpy + * @param dst Zeiger auf den Speicherbereich der len breite Zeichen aufnehmen + * kann. Es werden genau len Zeichen hineingeschrieben. + * @param src Quellstring + * @param len Anzahl der Zeichen, die in dst geschrieben werden sollen. + * + * @return Zeiger auf das letzte geschriebene Byte, also immer dst + len - 1 + */ +wchar_t* wcpncpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + for (; len--; dst++, src++) { + if (!(*dst = *src)) { + wchar_t *ret = dst; + while (len--) { + *++dst = L'\0'; + } + return ret; + } + } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscasecmp.c b/src/modules/lib/stdlibc/wstring/wcscasecmp.c new file mode 100644 index 0000000..32bc3a5 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscasecmp.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2009 David Schultz <das at FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> +#include <wctype.h> + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen inklusive abschliessendes L'\0'. Diese + * Funktion ist das Pendant zu strcasecmp. + * + * @see strcasecmp + * @see wcscmp + * @see towlower + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscasecmp(const wchar_t* wcs1, const wchar_t* wcs2) +{ + wchar_t wc1, wc2; + + for (; *wcs1; wcs1++, wcs2++) { + wc1 = towlower(*wcs1); + wc2 = towlower(*wcs2); + if (wc1 != wc2) { + return (int) (wc1 - wc2); + } + } + + return -*wcs2; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscat.c b/src/modules/lib/stdlibc/wstring/wcscat.c new file mode 100644 index 0000000..a6e3917 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscat.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include <wchar.h> + + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei wird der Inhalt von + * src inklusive dem abschliessenden L'\0' ans Ende von dst kopiert. Der + * Aufrufer muss sicherstellen, dass nach dst genug Speicher frei ist. Diese + * Funktion ist das Pendant zu strcat. + * + * @see strcat + * @see wcsncat + * @param dst Zeiger auf den String an dessen Ende src angehaengt werden soll. + * @param src Zeiger auf den String der an dst angehaengt werden soll. + * + * @return dst + */ +wchar_t* wcscat(wchar_t* dst, const wchar_t* src) +{ + wchar_t* wcp; + + wcp = dst; + while (*wcp != L'\0') { + wcp++; + } + while ((*wcp++ = *src++) != L'\0') { } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcschr.c b/src/modules/lib/stdlibc/wstring/wcschr.c new file mode 100644 index 0000000..d5a49c9 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcschr.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * Erstes Vorkommen eines breiten Zeichens aus einem String aus breiten Zeichen + * heraussuchen. Diese Funktion ist das Pendant zu strchr. + * + * @see strchr + * @param wcs Zeiger auf den String in dem gesucht werden soll. + * @param wc Zeichen das gesucht werden soll. + * + * @return Zeiger auf das erste gefundene Zeichen oder NULL wenn keines gefunden + * wurde. + */ +wchar_t* wcschr(const wchar_t* wcs, wchar_t wc) +{ + while (*wcs != wc && *wcs != L'\0') { + wcs++; + } + + if (*wcs == wc) { + return (wchar_t*) wcs; + } + + return NULL; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscmp.c b/src/modules/lib/stdlibc/wstring/wcscmp.c new file mode 100644 index 0000000..a156009 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscmp.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * Zwei Strings aus breiten Zeichen inklusive dem abschliessenden L'\0' + * vergleichen. Diese Funktion ist das Pendant zu strcmp. + * + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcscmp(const wchar_t* wcs1, const wchar_t* wcs2) +{ + while (*wcs1 == *wcs2++) { + if (*wcs1++ == L'\0') { + return 0; + } + } + + return (*(unsigned int *)wcs1 - *(unsigned int *)--wcs2); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscoll.c b/src/modules/lib/stdlibc/wstring/wcscoll.c new file mode 100644 index 0000000..8f0ce49 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscoll.c @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * TODO + */ +int wcscoll(const wchar_t* wcs1, const wchar_t* wcs2) +{ + return wcscmp(wcs1, wcs2); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscpy.c b/src/modules/lib/stdlibc/wstring/wcscpy.c new file mode 100644 index 0000000..c25fb53 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscpy.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp + */ + +#include <wchar.h> + + +/** + * String aus Breiten Zeichen inklusive abschliessendem L'\0' kopieren. Der + * Aufrufer hat sicherzustellen, dass dst genug Platz bietet. Die beiden Strings + * duerfen sich nicht uberlappen. Diese Funktion ist das Pendant zu strcpy. + * + * @see strcpy + * @see wcsncpy + * @see wcpcpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den String der kopiert werden soll. + * + * @return dst + */ +wchar_t* wcscpy(wchar_t* dst, const wchar_t* src) +{ + wchar_t* wcp; + + wcp = dst; + while ((*wcp++ = *src++) != L'\0') { } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcscspn.c b/src/modules/lib/stdlibc/wstring/wcscspn.c new file mode 100644 index 0000000..45f8023 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcscspn.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include <wchar.h> + + +/** + * String aus breiten Zeichen nach einem Vorkommen eines Zeichens aus set + * durchsuchen. Diese Funktion ist das Pendant zu strcspn. + * + * @see strcspn + * @see wcsspn + * @param wcs Zeiger auf den String, dar durchsucht werden soll + * @param set Zeiger auf den String mit den zu suchenden Zeichen. + * + * @return Offset vom Anfang des Strings oder wcslen(wcs) wenn kein Vorkommen + * gefunden wurde. + */ +size_t wcscspn(const wchar_t* wcs, const wchar_t* set) +{ + const wchar_t* p; + const wchar_t* q; + + p = wcs; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + goto done; + } + q++; + } + p++; + } + +done: + return (p - wcs); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsdup.c b/src/modules/lib/stdlibc/wstring/wcsdup.c new file mode 100644 index 0000000..2f94511 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsdup.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2005 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <stdlib.h> +#include <wchar.h> + +/** + * String aus breiten Zeichen in einen neu allozierten Speicherbereich kopieren. + * Diese Funktion ist das Pendant zu strdup. + * + * @see strdup + * @param wcs Zeiger auf den zu kopierenden String + * + * @return Zeiger auf die Kopie. Muss vom Aufrufer freigegeben werden. Im + * Fehlerfall NULL. + */ +wchar_t* wcsdup(const wchar_t* wcs) +{ + wchar_t* copy; + size_t len; + + len = wcslen(wcs) + 1; + if ((copy = malloc(len * sizeof(wchar_t))) == NULL) { + return NULL; + } + + return wmemcpy(copy, wcs, len); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcslcat.c b/src/modules/lib/stdlibc/wstring/wcslcat.c new file mode 100644 index 0000000..85bc8e4 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcslcat.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp + */ + +#include <wchar.h> + + +/** + * Kopiert src an das Ende des Strings dst. Dabei wird der String dst auf + * maximal len - 1 Zeichen und L'\0' verlaengert, ausser wenn len == 0. + * + * @see wcsncat + * @param dst Zeiger auf String an den src angehaengt werden soll + * @param src Zeiger auf String der an dst angehaengt werden soll + * @param len Anzahl Zeichen auf die dst Maximal verlaengert werden darf + * inklusiv L'\0.' + * + * @return wcslen(urspruengliches dst) + wcslen(src); Wenn der Rueckgabewert >= + * len ist, wurde src nich vollstaendig kopiert. + */ +size_t wcslcat(wchar_t* dst, const wchar_t* src, size_t len) +{ + wchar_t* d = dst; + const wchar_t* s = src; + size_t n = len; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != L'\0' && n-- != 0) { + d++; + } + dlen = d - dst; + n = len - dlen; + + if (n == 0) { + return(dlen + wcslen(s)); + } + while (*s != L'\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = L'\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + diff --git a/src/modules/lib/stdlibc/wstring/wcslcpy.c b/src/modules/lib/stdlibc/wstring/wcslcpy.c new file mode 100644 index 0000000..a172f96 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcslcpy.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller at courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp + */ + +#include <wchar.h> + + +/** + * Kopiert einen String aus breiten Zeichen. Dabei werden maximal len - 1 + * Zeichen kopiert, und dst wird immer mit L'\0' terminiert, wenn len != 0 ist. + * + * @see wcscpy + * @param dst Zeiger auf den Speicherbereich in dem die Kopie abgelegt werden + * soll. + * @param src Zeiger auf den Quellstring + * @param len Anzahl der Zeichen inklusiv abschliessendes L'\0', die maximal in + * dst geschrieben werden sollen. + * + * @return wcslen(src); Wenn der Rueckgabewert <= len ist, wurde src nicht + * vollstaendig kopiert. + */ +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + wchar_t* d = dst; + const wchar_t* s = src; + size_t n = len; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) { + break; + } + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (len != 0) { + *d = '\0'; /* NUL-terminate dst */ + } + while (*s++) { } + } + + return(s - src - 1); /* count does not include NUL */ +} + diff --git a/src/modules/lib/stdlibc/wstring/wcslen.c b/src/modules/lib/stdlibc/wstring/wcslen.c new file mode 100644 index 0000000..1d80076 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcslen.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include <wchar.h> + + +/** + * Laenge eines Strings aus breiten Zeichen bestimmen. Dabei werden die Zeichen + * gezaehlt, bis ein abschliessendes L'\0' gefunden wird. Das L'\0' wird nicht + * mitgezaehlt. Diese Funktion ist das Pendant zu strlen. + * + * @see strlen + * @param wcs Zeiger auf den String + * + * @return Laenge des Strings in Zeichen + */ +size_t wcslen(const wchar_t* wcs) +{ + const wchar_t* p; + + p = wcs; + while (*p) { + p++; + } + + return p - wcs; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncasecmp.c b/src/modules/lib/stdlibc/wstring/wcsncasecmp.c new file mode 100644 index 0000000..05ecb5b --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncasecmp.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2009 David Schultz <das at FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> +#include <wctype.h> + + +/** + * Zwei Strings aus breiten Zeichen ohne Unterscheidung von + * Gross-/Kleinschreibung vergleichen. Dabei werden maximal die ersten len + * Zeichen von Beiden Strings verglichen. Diese Funktion ist das Pendant zu + * strncasecmp. + * + * @see strncasecmp + * @see wcscasecmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein L'\0' gefunden wird. + * + * @return 0 wenn die beiden Strings gleich sind, < 0 wenn das Zeichen in wcs2 + * groesser ist als das in wcs1 und > 0 wenn das Zeichen in wcs1 + * groesser ist als das in wcs2. + */ +int wcsncasecmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len) +{ + wchar_t wc1, wc2; + + if (len == 0) { + return 0; + } + + for (; *wcs1; wcs1++, wcs2++) { + wc1 = towlower(*wcs1); + wc2 = towlower(*wcs2); + if (wc1 != wc2) { + return ((int) wc1 - wc2); + } + + if (--len == 0) { + return 0; + } + } + + return -*wcs2; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncat.c b/src/modules/lib/stdlibc/wstring/wcsncat.c new file mode 100644 index 0000000..874866e --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncat.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include <wchar.h> + + +/** + * Zwei Strings aus breiten Zeichen aneinanderhaengen. Dabei werden maximal len + * Zeichen aus src kopiert. Der Aufrufer muss sicherstellen, dass nach dem + * String, auf den dst zeigt, noch mindestens len + 1 Zeichen platz haben. dst + * wird in jedem Fall mit L'\0' terminiert. Diese Funktion ist das Pendant zu + * strncat. + * + * @see strncat + * @see wcscat + * @param dst String an den src angehaengt werden soll + * @param src String der an dst angehaengt werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden aus src + * + * @return dst + */ +wchar_t* wcsncat(wchar_t* dst, const wchar_t* src, size_t len) +{ + wchar_t* p; + wchar_t* q; + const wchar_t* r; + + p = dst; + while (*p) { + p++; + } + + q = p; + r = src; + while (*r && len) { + *q++ = *r++; + len--; + } + *q = '\0'; + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncmp.c b/src/modules/lib/stdlibc/wstring/wcsncmp.c new file mode 100644 index 0000000..bc37bab --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncmp.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * Zwei Strings aus breiten Zeichen vergleichen. Dabei werden maximal len + * Zeichen verglichen. Diese Funktion ist das Pendant zu strncmp. + * + * @see strncmp + * @see wcscmp + * @param wcs1 Erster String + * @param wcs2 Zweiter String + * @param len Anzahl der Zeichen, die maximal verglichen werden sollen, wenn + * vorher kein abschliessendes L'\0' angetroffen wurde. + * + * @return 0 wenn die Strings gleich sind, oder <0 wenn das erste + * ungleiche Zeichen in wcs1 kleiner ist als das in wcs2, ist es + * groesser >0. + */ +int wcsncmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len) +{ + + if (len == 0) { + return 0; + } + + do { + if (*wcs1 != *wcs2++) { + /* XXX assumes wchar_t = int */ + return (*(unsigned int*)wcs1 - *(unsigned int*)--wcs2); + } + + if (*wcs1++ == 0) { + break; + } + } while (--len != 0); + return 0; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsncpy.c b/src/modules/lib/stdlibc/wstring/wcsncpy.c new file mode 100644 index 0000000..9bad4dc --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsncpy.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * String aus breiten Zeichen kopieren. Dabei werden maximal len Zeichen + * kopiert. Die restlichen Zeichen im Puffer werden mit L'\0' gefuellt. Ist src + * gleich lang wie oder laenger als len, wird dst nicht mit L'\0' terminiert. + * Die beiden Strings duerfen sich nicht ueberlappen. Diese Funktion ist das + * Pendant zu strncpy. + * + * @see strncpy + * @see wcscpy + * @param src String der kopiert werden soll + * @param dst Zeiger auf den Speicherbereich in den src kopiert werden soll + * @param len Anzahl der Zeichen, die maximal kopiert werden sollen + * + * @return dst + */ +wchar_t* wcsncpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + if (len != 0) { + wchar_t* d = dst; + const wchar_t* s = src; + + do { + if ((*d++ = *s++) == L'\0') { + /* NUL pad the remaining n-1 bytes */ + while (--len != 0) { + *d++ = L'\0'; + } + break; + } + } while (--len != 0); + } + + return dst; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsnlen.c b/src/modules/lib/stdlibc/wstring/wcsnlen.c new file mode 100644 index 0000000..07c09a9 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsnlen.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2009 David Schultz <das at FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * Laenge eines Strings aus breiten Zeichen errechnen. Dabei werden maximal max + * Zeichen gezaehlt. Diese Funktion ist das Pendant zu strnlen. + * + * @see strnlen + * @see wcslen + * @param wcs String + * @param max Anzahl der Zeichen, die maximal gezaehlt werden sollen + * + * @return Anzahl der Zeichen ohne abschliessendes L'\0' + */ +size_t wcsnlen(const wchar_t* wcs, size_t max) +{ + size_t len; + + for (len = 0; len < max; len++, wcs++) { + if (!*wcs) { + break; + } + } + + return len; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcspbrk.c b/src/modules/lib/stdlibc/wstring/wcspbrk.c new file mode 100644 index 0000000..bc9c594 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcspbrk.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include <wchar.h> + + +/** + * Erstes vorkommen eines breiten Zeichens aus set im String aus breiten Zeichen + * wcs suchen. Diese Funktion ist das Pendant zu strpbrk. + * + * @see strpbrk + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set String aus Zeichen nach denen gesucht werden soll + * + * @return Zeiger auf die Position an der ein Zeichen gefunden wurde oder NULL + * falls keines gefunden wurde. + */ +wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* set) +{ + const wchar_t* p; + const wchar_t* q; + + p = wcs; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + /* LINTED interface specification */ + return (wchar_t*) p; + } + q++; + } + p++; + } + + return NULL; +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsrchr.c b/src/modules/lib/stdlibc/wstring/wcsrchr.c new file mode 100644 index 0000000..23d3a65 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsrchr.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * Letztes Vorkommen eines breiten Zeichens in einem String aus breiten Zeichen + * suchen. Diese Funktion ist das Pendant zu strrchr. + * + * @see strrchr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param wc Zeichen das gesucht werden soll + * + * @return Zeiger auf das letzte gefundene Vorkommen, oder NULL falls das + * Zeichen nicht gefunden wurde. + */ +wchar_t* wcsrchr(const wchar_t* wcs, wchar_t wc) +{ + const wchar_t* last; + + last = NULL; + for (;;) { + if (*wcs == wc) { + last = wcs; + } + + if (*wcs == L'\0') { + break; + } + wcs++; + } + + return ((wchar_t*) last); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsspn.c b/src/modules/lib/stdlibc/wstring/wcsspn.c new file mode 100644 index 0000000..398af6f --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsspn.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include <wchar.h> + + +/** + * Durchsucht einen String aus breiten Zeichen nach dem ersten Zeichen das nicht + * in set vorkommt. Diese Funktion ist das Pendant zu strspn. + * + * @see strspn + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param set Zeichen die zugelassen sind + * + * @return Offset des ersten Zeichens das nicht in set vorkommt, oder + * wcslen(wcs) falls alle Zeichen in set enthalten sind. + */ +size_t wcsspn(const wchar_t* wcs, const wchar_t* set) +{ + const wchar_t* p; + const wchar_t* q; + + p = wcs; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + break; + } + q++; + } + if (!*q) { + goto done; + } + p++; + } + +done: + return (p - wcs); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcsstr.c b/src/modules/lib/stdlibc/wstring/wcsstr.c new file mode 100644 index 0000000..5e8357c --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcsstr.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <wchar.h> + +/** + * Erstes Vorkommen des Breiten Strings find in wcs suchen. Diese Funktion ist + * das Pendant zu strstr. + * + * @see strstr + * @see wcschr + * @param wcs String der durchsucht werden soll + * @param find String der gesucht werden soll + * + * @return Zeiger auf das erste Vorkommen in wcs oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wcsstr(const wchar_t* wcs, const wchar_t* find) +{ + wchar_t c, sc; + size_t len; + + if ((c = *find++) != L'\0') { + len = wcslen(find); + do { + do { + if ((sc = *wcs++) == L'\0') { + return NULL; + } + } while (sc != c); + } while (wcsncmp(wcs, find, len) != 0); + wcs--; + } + + return ((wchar_t*) wcs); +} + diff --git a/src/modules/lib/stdlibc/wstring/wcstok.c b/src/modules/lib/stdlibc/wstring/wcstok.c new file mode 100644 index 0000000..e067ee9 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wcstok.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters <wes at softweyr.com> + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notices, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notices, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE + * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <wchar.h> + + +/** + * String aus breiten Zeichen in Tokens aufspalten, die durch die in delim + * angegebenen Zeichen getrennt werden. wcs wird dabei veraendert. Ist wcs != + * NULL beginnt die suche dort, sonst wird bei *last begonnen. *last wird + * jeweils auf den Anfang des naechsten Token gesetzt, oder auf NULL, wenn das + * Ende erreicht wurde. + * Diese Funktion ist das Pendant zu strtok. + * + * @see strtok + * @param wcs Zeiger auf das Zeichen bei dem die Zerlegung in Tokens begonnen + * werden soll, oder NULL, wenn der Wert von *last genommen werden + * soll. + * @param delim Zeichen die zwei Tokens voneinander trennen koennen + * @param last Zeiger auf die Speicherstelle an der die Funktion die Position + * des naechsten token speichern kann fuer den internen Gebrauch, + * um beim Naechsten Aufruf mit wcs == NULL das naechste Token + * zurueck geben zu koennen. + * + * @return Zeiger auf das aktuelle Token, oder NULL wenn keine Tokens mehr + * vorhanden sind. + */ +wchar_t* wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** last) +{ + const wchar_t* spanp; + wchar_t* tok; + wchar_t c, sc; + + if (wcs == NULL && (wcs = *last) == NULL) { + return NULL; + } + + /* + * Skip (span) leading delimiters (wcs += wcsspn(wcs, delim), sort of). + */ +cont: + c = *wcs++; + for (spanp = delim; (sc = *spanp++) != L'\0';) { + if (c == sc) { + goto cont; + } + } + + if (c == L'\0') { /* no non-delimiter characters */ + *last = NULL; + return NULL; + } + tok = wcs - 1; + + /* + * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *wcs++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == L'\0') { + wcs = NULL; + } else { + wcs[-1] = L'\0'; + } + *last = wcs; + + return tok; + } + } while (sc != L'\0'); + } + /* NOTREACHED */ +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemchr.c b/src/modules/lib/stdlibc/wstring/wmemchr.c new file mode 100644 index 0000000..481ccdc --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemchr.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include <wchar.h> + + +/** + * Speicherbereich aus breiten Zeichen nach einem bestimmten Zeichen + * durchsuchen. Diese Funktion ist das Pendant zu memchr. + * + * @see memchr + * @see wcschr + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zu suchendes Zeichen + * @param len Laenge des Speicherbereichs + * + * @return Zeiger auf das gefundene Zeichen oder NULL falls keines gefunden + * wurde. + */ +wchar_t* wmemchr(const wchar_t* wcs, wchar_t wc, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) { + if (*wcs == wc) { + /* LINTED const castaway */ + return (wchar_t*) wcs; + } + wcs++; + } + + return NULL; +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemcmp.c b/src/modules/lib/stdlibc/wstring/wmemcmp.c new file mode 100644 index 0000000..c8412e7 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemcmp.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include <wchar.h> + + +/** + * Zwei Speicherbereiche aus breiten Zeichen vergleichen. Diese Funktion ist das + * Pendant zu memcmp. + * + * @see memcmp + * @see wcscpm + * @see wcsncmp + * @param wcs1 Zeiger auf den ersten Speicherbereich + * @param wcs2 Zeiger auf den zweiten Speicherbereich + * @param len Laenge der beiden Speicherbereiche + * + * @return 0 wenn die beiden Speicherbereiche gleich sind, < 0 wenn das erste + * unterschiedliche Zeichen in wcs1 kleiner ist als das + * Korrespondierende in wcs2 oder > 0 wenn es groesser ist. + */ +int wmemcmp(const wchar_t* wcs1, const wchar_t* wcs2, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) { + if (*wcs1 != *wcs2) { + /* wchar might be unsigned */ + return *wcs1 > *wcs2 ? 1 : -1; + } + + wcs1++; + wcs2++; + } + return 0; +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemcpy.c b/src/modules/lib/stdlibc/wstring/wmemcpy.c new file mode 100644 index 0000000..072c5f4 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemcpy.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include <string.h> +#include <wchar.h> + + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich nicht ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memcpy + * @see wcsncpy + * @see wcscpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemcpy(wchar_t* dst, const wchar_t* src, size_t len) +{ + return (wchar_t*) memcpy(dst, src, len * sizeof(wchar_t)); +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemmove.c b/src/modules/lib/stdlibc/wstring/wmemmove.c new file mode 100644 index 0000000..8da074d --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemmove.c @@ -0,0 +1,49 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include <string.h> +#include <wchar.h> + + +/** + * Speicherbereich aus breiten Zeichen kopieren. Die beiden Speicherbereiche + * duerfen sich ueberlappen. Diese Funktion ist das Pendant zu memcpy. + * + * @see memmove + * @see wmemcpy + * @param dst Speicherbereich in den kopiert werden soll + * @param src Speicherbereich der kopiert werden soll + * @param len Laenge der Speicherbereiche + * + * @return dst + */ +wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t len) +{ + return (wchar_t*) memmove(dst, src, len * sizeof(wchar_t)); +} + diff --git a/src/modules/lib/stdlibc/wstring/wmemset.c b/src/modules/lib/stdlibc/wstring/wmemset.c new file mode 100644 index 0000000..e45ab60 --- /dev/null +++ b/src/modules/lib/stdlibc/wstring/wmemset.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include <wchar.h> + + +/** + * Speicherbereich aus breiten Zeichen mit einem bestimmten Zeichen ausfuellen. + * Diese Funktion ist das pendant zu memset. + * + * @see memset + * @param wcs Zeiger auf den Speicherbereich + * @param wc Zeichen mit dem der Speicherbereich gefuellt werden soll + * @param len Laenge des Speicherbereichs + * + * @return wcs + */ +wchar_t* wmemset(wchar_t* wcs, wchar_t wc, size_t len) +{ + size_t i; + wchar_t* p; + + p = wcs; + for (i = 0; i < len; i++) { + *p = wc; + p++; + } + + return wcs; +} + -- 1.6.0.6