summaryrefslogtreecommitdiff
path: root/libc/string/string.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2001-06-02 21:46:42 +0000
committerManuel Novoa III <mjn3@codepoet.org>2001-06-02 21:46:42 +0000
commitd85536af73dc5d327075d983abfa69d70e129d20 (patch)
tree21e6939a55be15151ab986f945a52587b950cf89 /libc/string/string.c
parent4f8c656e408ff31d081c8f1302cb7adff409ebb8 (diff)
Add locale-enabled strcoll function from vodz, plus supporting tool.
Diffstat (limited to 'libc/string/string.c')
-rw-r--r--libc/string/string.c31
1 files changed, 31 insertions, 0 deletions
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 ************************************/