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/locale/wctrans.c
          +++ new/usr/src/lib/libc/port/locale/wctrans.c
   1    1  /*
        2 + * Copyright 2013 Garrett D'Amore <garrett@damore.org>
   2    3   * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3    4   * Copyright (c) 2002 Tim J. Robbins.
   4    5   * All rights reserved.
   5    6   *
   6    7   * Redistribution and use in source and binary forms, with or without
   7    8   * modification, are permitted provided that the following conditions
   8    9   * are met:
   9   10   * 1. Redistributions of source code must retain the above copyright
  10   11   *    notice, this list of conditions and the following disclaimer.
  11   12   * 2. Redistributions in binary form must reproduce the above copyright
↓ open down ↓ 7 lines elided ↑ open up ↑
  19   20   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20   21   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21   22   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22   23   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23   24   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24   25   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25   26   * SUCH DAMAGE.
  26   27   */
  27   28  
  28   29  #include "lint.h"
       30 +#include <note.h>
  29   31  #include <errno.h>
  30   32  #include <string.h>
  31   33  #include <wctype.h>
       34 +#include <locale.h>
  32   35  
  33   36  enum {
  34   37          _WCT_ERROR      = 0,
  35   38          _WCT_TOLOWER    = 1,
  36   39          _WCT_TOUPPER    = 2
  37   40  };
  38   41  
  39   42  wint_t
  40      -towctrans(wint_t wc, wctrans_t desc)
       43 +towctrans_l(wint_t wc, wctrans_t desc, locale_t loc)
  41   44  {
  42      -
  43   45          switch (desc) {
  44   46          case _WCT_TOLOWER:
  45      -                wc = towlower(wc);
       47 +                wc = towlower_l(wc, loc);
  46   48                  break;
  47   49          case _WCT_TOUPPER:
  48      -                wc = towupper(wc);
       50 +                wc = towupper_l(wc, loc);
  49   51                  break;
  50   52          case _WCT_ERROR:
  51   53          default:
  52   54                  errno = EINVAL;
  53   55                  break;
  54   56          }
  55   57  
  56   58          return (wc);
  57   59  }
  58   60  
       61 +wint_t
       62 +towctrans(wint_t wc, wctrans_t desc)
       63 +{
       64 +        return (towctrans_l(wc, desc, uselocale(NULL)));
       65 +}
       66 +
       67 +/*
       68 + * For *now* we don't support locale sensitive transforms besides toupper
       69 + * and tolower.
       70 + */
  59   71  wctrans_t
  60      -wctrans(const char *charclass)
       72 +wctrans_l(const char *charclass, locale_t loc)
  61   73  {
  62   74          struct {
  63   75                  const char      *name;
  64   76                  wctrans_t        trans;
  65   77          } ccls[] = {
  66   78                  { "tolower",    _WCT_TOLOWER },
  67   79                  { "toupper",    _WCT_TOUPPER },
  68   80                  { NULL,         _WCT_ERROR },           /* Default */
  69   81          };
  70   82          int i;
       83 +        _NOTE(ARGUNUSED(loc));
  71   84  
  72   85          i = 0;
  73   86          while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0)
  74   87                  i++;
  75   88  
  76   89          if (ccls[i].trans == _WCT_ERROR)
  77   90                  errno = EINVAL;
  78   91          return (ccls[i].trans);
       92 +}
       93 +
       94 +wctrans_t
       95 +wctrans(const char *charclass)
       96 +{
       97 +        return (wctrans_l(charclass, uselocale(NULL)));
  79   98  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX