Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>

*** 18,27 **** --- 18,28 ---- * * 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,65 **** #include "lint.h" #include <sys/types.h> #include <strings.h> #include <ctype.h> int ! strncasecmp(const char *s1, const char *s2, size_t n) { - extern int charset_is_ascii; extern int ascii_strncasecmp(const char *s1, const char *s2, size_t n); ! int *cm; const uchar_t *us1; const uchar_t *us2; /* * 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) return (ascii_strncasecmp(s1, s2, n)); ! cm = __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)]); } --- 34,75 ---- #include "lint.h" #include <sys/types.h> #include <strings.h> #include <ctype.h> + #include <locale.h> + #include "lctype.h" + #include "localeimpl.h" int ! strncasecmp_l(const char *s1, const char *s2, size_t n, locale_t loc) { extern int ascii_strncasecmp(const char *s1, const char *s2, size_t n); ! 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 (lct->lc_is_ascii) return (ascii_strncasecmp(s1, s2, n)); ! 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))); }