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/gb18030.c
          +++ new/usr/src/lib/libc/port/locale/gb18030.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
   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 ↓ 15 lines elided ↑ open up ↑
  27   28  
  28   29  /*
  29   30   * PRC National Standard GB 18030-2000 encoding of Chinese text.
  30   31   *
  31   32   * See gb18030(5) for details.
  32   33   */
  33   34  
  34   35  #include "lint.h"
  35   36  #include <sys/types.h>
  36   37  #include <errno.h>
  37      -#include "runetype.h"
  38   38  #include <stdlib.h>
  39   39  #include <string.h>
  40   40  #include <wchar.h>
  41   41  #include "mblocal.h"
       42 +#include "lctype.h"
  42   43  
  43   44  
  44   45  static size_t   _GB18030_mbrtowc(wchar_t *_RESTRICT_KYWD,
  45   46                      const char *_RESTRICT_KYWD,
  46   47                      size_t, mbstate_t *_RESTRICT_KYWD);
  47   48  static int      _GB18030_mbsinit(const mbstate_t *);
  48   49  static size_t   _GB18030_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
  49   50                      mbstate_t *_RESTRICT_KYWD);
       51 +static size_t   _GB18030_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
       52 +                    const char **_RESTRICT_KYWD, size_t, size_t,
       53 +                    mbstate_t *_RESTRICT_KYWD);
       54 +static size_t   _GB18030_wcsnrtombs(char *_RESTRICT_KYWD,
       55 +                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
       56 +                    mbstate_t *_RESTRICT_KYWD);
  50   57  
       58 +
  51   59  typedef struct {
  52   60          int     count;
  53   61          uchar_t bytes[4];
  54   62  } _GB18030State;
  55   63  
  56      -int
  57      -_GB18030_init(_RuneLocale *rl)
       64 +void
       65 +_GB18030_init(struct lc_ctype *lct)
  58   66  {
  59   67  
  60      -        __mbrtowc = _GB18030_mbrtowc;
  61      -        __wcrtomb = _GB18030_wcrtomb;
  62      -        __mbsinit = _GB18030_mbsinit;
  63      -        _CurrentRuneLocale = rl;
  64      -        __ctype[520] = 4;
  65      -        charset_is_ascii = 0;
  66      -
  67      -        return (0);
       68 +        lct->lc_mbrtowc = _GB18030_mbrtowc;
       69 +        lct->lc_wcrtomb = _GB18030_wcrtomb;
       70 +        lct->lc_mbsinit = _GB18030_mbsinit;
       71 +        lct->lc_mbsnrtowcs = _GB18030_mbsnrtowcs;
       72 +        lct->lc_wcsnrtombs = _GB18030_wcsnrtombs;
       73 +        lct->lc_max_mblen = 4;
       74 +        lct->lc_is_ascii = 0;
  68   75  }
  69   76  
  70   77  static int
  71   78  _GB18030_mbsinit(const mbstate_t *ps)
  72   79  {
  73   80  
  74   81          return (ps == NULL || ((const _GB18030State *)ps)->count == 0);
  75   82  }
  76   83  
  77   84  static size_t
↓ open down ↓ 135 lines elided ↑ open up ↑
 213  220          } else if (wc <= 0x7f) {
 214  221                  *s++ = wc;
 215  222                  len = 1;
 216  223          } else
 217  224                  goto ilseq;
 218  225  
 219  226          return (len);
 220  227  ilseq:
 221  228          errno = EILSEQ;
 222  229          return ((size_t)-1);
      230 +}
      231 +
      232 +static size_t
      233 +_GB18030_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
      234 +    const char **_RESTRICT_KYWD src, size_t nms, size_t len,
      235 +    mbstate_t *_RESTRICT_KYWD ps)
      236 +{
      237 +        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _GB18030_mbrtowc));
      238 +}
      239 +
      240 +static size_t
      241 +_GB18030_wcsnrtombs(char *_RESTRICT_KYWD dst,
      242 +    const wchar_t **_RESTRICT_KYWD src, size_t nwc, size_t len,
      243 +    mbstate_t *_RESTRICT_KYWD ps)
      244 +{
      245 +        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _GB18030_wcrtomb));
 223  246  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX