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,33 +34,42 @@
#include "lint.h"
#include <sys/types.h>
#include <strings.h>
#include <ctype.h>
+#include <locale.h>
+#include "lctype.h"
+#include "localeimpl.h"
int
-strncasecmp(const char *s1, const char *s2, size_t n)
+strncasecmp_l(const char *s1, const char *s2, size_t n, locale_t loc)
{
- extern int charset_is_ascii;
extern int ascii_strncasecmp(const char *s1, const char *s2, size_t n);
- 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_strncasecmp() function.
*/
- if (charset_is_ascii)
+ if (lct->lc_is_ascii)
return (ascii_strncasecmp(s1, s2, n));
- cm = __trans_lower;
+ cm = lct->lc_trans_lower;
us1 = (const uchar_t *)s1;
us2 = (const uchar_t *)s2;
while (n != 0 && cm[*us1] == cm[*us2++]) {
if (*us1++ == '\0')
return (0);
n--;
}
return (n == 0 ? 0 : cm[*us1] - cm[*(us2 - 1)]);
+}
+
+int
+strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ return (strncasecmp_l(s1, s2, n, uselocale(NULL)));
}