Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: TBD

@@ -18,10 +18,11 @@
  *
  * CDDL HEADER END
  */
 
 /*
+ * Copyright 2013 Garrett D'Amore <garrett@damore.org>
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T     */
 /*        All Rights Reserved   */

@@ -33,31 +34,41 @@
 
 #include "lint.h"
 #include <sys/types.h>
 #include <strings.h>
 #include <ctype.h>
+#include <locale.h>
+#include "localeimpl.h"
+#include "lctype.h"
 
 int
-strcasecmp(const char *s1, const char *s2)
+strcasecmp_l(const char *s1, const char *s2, locale_t loc)
 {
-        extern int charset_is_ascii;
         extern int ascii_strcasecmp(const char *s1, const char *s2);
-        int *cm;
+        const int *cm;
         const uchar_t *us1;
         const uchar_t *us2;
+        const struct lc_ctype *lct = loc->ctype;
 
         /*
          * If we are in a locale that uses the ASCII character set
          * (C or POSIX), use the fast ascii_strcasecmp() function.
          */
-        if (charset_is_ascii)
+        if (lct->lc_is_ascii)
                 return (ascii_strcasecmp(s1, s2));
 
-        cm = __trans_lower;
+        cm = lct->lc_trans_lower;
         us1 = (const uchar_t *)s1;
         us2 = (const uchar_t *)s2;
 
         while (cm[*us1] == cm[*us2++])
                 if (*us1++ == '\0')
                         return (0);
         return (cm[*us1] - cm[*(us2 - 1)]);
+}
+
+int
+strcasecmp(const char *s1, const char *s2)
+{
+        /* would be nice to avoid uselocale()... but I don't see how */
+        return (strcasecmp_l(s1, s2, uselocale(NULL)));
 }