diff options
Diffstat (limited to 'libc/string')
-rw-r--r-- | libc/string/Makefile | 4 | ||||
-rw-r--r-- | libc/string/string.c | 31 |
2 files changed, 35 insertions, 0 deletions
diff --git a/libc/string/Makefile b/libc/string/Makefile index e2d04c3f9..48d3a3426 100644 --- a/libc/string/Makefile +++ b/libc/string/Makefile @@ -28,6 +28,10 @@ MOBJ=strlen.o strcat.o strcpy.o strchr.o strcmp.o strncat.o strncpy.o \ strncmp.o strrchr.o strdup.o memcpy.o memccpy.o memset.o \ memmove.o memcmp.o memchr.o ffs.o strnlen.o strxfrm.o +ifeq ($(HAS_LOCALE),true) + MOBJ += strcoll.o +endif + MSRC1=strsignal.c MOBJ1=strsignal.o psignal.o diff --git a/libc/string/string.c b/libc/string/string.c index b3070907c..0e2df303b 100644 --- a/libc/string/string.c +++ b/libc/string/string.c @@ -76,7 +76,38 @@ int strcmp(const char *s1, const char *s2) return c1 - c2; } +#ifndef __UCLIBC_HAS_LOCALE__ __asm__(".weak strcoll; strcoll = strcmp"); +#endif /* __UCLIBC_HAS_LOCALE__ */ +#endif + +/***** Function strcoll (locale only, as non-locale is alias of strcmp *****/ + +#ifdef L_strcoll +#ifdef __UCLIBC_HAS_LOCALE__ + +#include "../misc/locale/_locale.h" + +const unsigned char *_uc_collate_b; /* NULL for no collate, strcoll->strcmp */ + +int strcoll(const char *s1, const char *s2) +{ + unsigned char c1, c2; + + while(1) { + c1 = (unsigned char) *s1; + c2 = (unsigned char) *s2; + if(_uc_collate_b) { /* setuped non-C locale? */ + c1 = _uc_collate_b[c1]; + c2 = _uc_collate_b[c2]; + } + if (*s1 == '\0' || c1 != c2) + return c1 - c2; + s1++; + s2++; + } +} +#endif /* __UCLIBC_HAS_LOCALE__ */ #endif /********************** Function strncat ************************************/ |