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/locale/big5.c
          +++ new/usr/src/lib/libc/port/locale/big5.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-2004 Tim J. Robbins. All rights reserved.
   4    5   * Copyright (c) 1993
   5    6   *      The Regents of the University of California.  All rights reserved.
   6    7   *
   7    8   * This code is derived from software contributed to Berkeley by
   8    9   * Paul Borman at Krystal Technologies.
   9   10   *
  10   11   * Redistribution and use in source and binary forms, with or without
  11   12   * modification, are permitted provided that the following conditions
↓ open down ↓ 16 lines elided ↑ open up ↑
  28   29   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29   30   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30   31   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31   32   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32   33   * SUCH DAMAGE.
  33   34   */
  34   35  
  35   36  #include "lint.h"
  36   37  #include <sys/types.h>
  37   38  #include <errno.h>
  38      -#include "runetype.h"
  39   39  #include <stdlib.h>
  40   40  #include <string.h>
  41   41  #include <wchar.h>
  42   42  #include "mblocal.h"
       43 +#include "lctype.h"
  43   44  
  44   45  static size_t   _BIG5_mbrtowc(wchar_t *_RESTRICT_KYWD,
  45   46                      const char *_RESTRICT_KYWD,
  46   47                      size_t, mbstate_t *RESTRICT_KYWD);
  47   48  static int      _BIG5_mbsinit(const mbstate_t *);
  48   49  static size_t   _BIG5_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
  49   50                      mbstate_t *_RESTRICT_KYWD);
       51 +static size_t   _BIG5_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
       52 +                    const char **_RESTRICT_KYWD, size_t, size_t,
       53 +                    mbstate_t *_RESTRICT_KYWD);
       54 +static size_t   _BIG5_wcsnrtombs(char *_RESTRICT_KYWD,
       55 +                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
       56 +                    mbstate_t *_RESTRICT_KYWD);
  50   57  
  51   58  typedef struct {
  52   59          wchar_t ch;
  53   60  } _BIG5State;
  54   61  
  55      -int
  56      -_BIG5_init(_RuneLocale *rl)
       62 +void
       63 +_BIG5_init(struct lc_ctype *lct)
  57   64  {
  58      -
  59      -        __mbrtowc = _BIG5_mbrtowc;
  60      -        __wcrtomb = _BIG5_wcrtomb;
  61      -        __mbsinit = _BIG5_mbsinit;
  62      -        _CurrentRuneLocale = rl;
  63      -        __ctype[520] = 2;
  64      -        charset_is_ascii = 0;
  65      -        return (0);
       65 +        lct->lc_mbrtowc = _BIG5_mbrtowc;
       66 +        lct->lc_wcrtomb = _BIG5_wcrtomb;
       67 +        lct->lc_mbsnrtowcs = _BIG5_mbsnrtowcs;
       68 +        lct->lc_wcsnrtombs = _BIG5_wcsnrtombs;
       69 +        lct->lc_mbsinit = _BIG5_mbsinit;
       70 +        lct->lc_max_mblen = 2;
       71 +        lct->lc_is_ascii = 0;
  66   72  }
  67   73  
  68   74  static int
  69   75  _BIG5_mbsinit(const mbstate_t *ps)
  70   76  {
  71   77  
  72   78          return (ps == NULL || ((const _BIG5State *)ps)->ch == 0);
  73   79  }
  74   80  
  75   81  static int
↓ open down ↓ 80 lines elided ↑ open up ↑
 156  162          if (s == NULL)
 157  163                  /* Reset to initial shift state (no-op) */
 158  164                  return (1);
 159  165          if (wc & 0x8000) {
 160  166                  *s++ = (wc >> 8) & 0xff;
 161  167                  *s = wc & 0xff;
 162  168                  return (2);
 163  169          }
 164  170          *s = wc & 0xff;
 165  171          return (1);
      172 +}
      173 +
      174 +static size_t
      175 +_BIG5_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
      176 +    size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
      177 +{
      178 +        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _BIG5_mbrtowc));
      179 +}
      180 +
      181 +static size_t
      182 +_BIG5_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
      183 +    size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps)
      184 +{
      185 +        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _BIG5_wcrtomb));
 166  186  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX