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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/i18n/strcasestr.c
          +++ new/usr/src/lib/libc/port/locale/strcasestr.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) 1988 AT&T */
  27   28  /*        All Rights Reserved   */
  28   29  
  29   30  #include "lint.h"
  30   31  #include <string.h>
  31   32  #include <ctype.h>
  32   33  #include <sys/types.h>
       34 +#include <locale.h>
       35 +#include "lctype.h"
       36 +#include "localeimpl.h"
  33   37  
  34   38  /*
  35   39   * strcasestr() locates the first occurrence in the string s1 of the
  36   40   * sequence of characters (excluding the terminating null character)
  37   41   * in the string s2, ignoring case.  strcasestr() returns a pointer
  38   42   * to the located string, or a null pointer if the string is not found.
  39   43   * If s2 is empty, the function returns s1.
  40   44   */
  41   45  
  42   46  char *
  43      -strcasestr(const char *s1, const char *s2)
       47 +strcasestr_l(const char *s1, const char *s2, locale_t loc)
  44   48  {
  45      -        int *cm = __trans_lower;
       49 +        const int *cm = loc->ctype->lc_trans_lower;
  46   50          const uchar_t *us1 = (const uchar_t *)s1;
  47   51          const uchar_t *us2 = (const uchar_t *)s2;
  48   52          const uchar_t *tptr;
  49   53          int c;
  50   54  
  51   55          if (us2 == NULL || *us2 == '\0')
  52   56                  return ((char *)us1);
  53   57  
  54   58          c = cm[*us2];
  55   59          while (*us1 != '\0') {
↓ open down ↓ 3 lines elided ↑ open up ↑
  59   63                                  continue;
  60   64                          if (c == '\0')
  61   65                                  return ((char *)tptr - 1);
  62   66                          us1 = tptr;
  63   67                          us2 = (const uchar_t *)s2;
  64   68                          c = cm[*us2];
  65   69                  }
  66   70          }
  67   71  
  68   72          return (NULL);
       73 +}
       74 +
       75 +char *
       76 +strcasestr(const char *s1, const char *s2)
       77 +{
       78 +        return (strcasestr_l(s1, s2, uselocale(NULL)));
  69   79  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX