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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/i18n/strcasecmp.c
          +++ new/usr/src/lib/libc/port/locale/strcasecmp.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
       23 + * Copyright 2013 Garrett D'Amore <garrett@damore.org>
  23   24   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24   25   */
  25   26  
  26   27  /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T     */
  27   28  /*        All Rights Reserved   */
  28   29  
  29   30  /*
  30   31   * Portions of this source code were derived from Berkeley 4.3 BSD
  31   32   * under license from the Regents of the University of California.
  32   33   */
  33   34  
  34   35  #include "lint.h"
  35   36  #include <sys/types.h>
  36   37  #include <strings.h>
  37   38  #include <ctype.h>
       39 +#include <locale.h>
       40 +#include "localeimpl.h"
       41 +#include "lctype.h"
  38   42  
  39   43  int
  40      -strcasecmp(const char *s1, const char *s2)
       44 +strcasecmp_l(const char *s1, const char *s2, locale_t loc)
  41   45  {
  42      -        extern int charset_is_ascii;
  43   46          extern int ascii_strcasecmp(const char *s1, const char *s2);
  44      -        int *cm;
       47 +        const int *cm;
  45   48          const uchar_t *us1;
  46   49          const uchar_t *us2;
       50 +        const struct lc_ctype *lct = loc->ctype;
  47   51  
  48   52          /*
  49   53           * If we are in a locale that uses the ASCII character set
  50   54           * (C or POSIX), use the fast ascii_strcasecmp() function.
  51   55           */
  52      -        if (charset_is_ascii)
       56 +        if (lct->lc_is_ascii)
  53   57                  return (ascii_strcasecmp(s1, s2));
  54   58  
  55      -        cm = __trans_lower;
       59 +        cm = lct->lc_trans_lower;
  56   60          us1 = (const uchar_t *)s1;
  57   61          us2 = (const uchar_t *)s2;
  58   62  
  59   63          while (cm[*us1] == cm[*us2++])
  60   64                  if (*us1++ == '\0')
  61   65                          return (0);
  62   66          return (cm[*us1] - cm[*(us2 - 1)]);
       67 +}
       68 +
       69 +int
       70 +strcasecmp(const char *s1, const char *s2)
       71 +{
       72 +        /* would be nice to avoid uselocale()... but I don't see how */
       73 +        return (strcasecmp_l(s1, s2, uselocale(NULL)));
  63   74  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX