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/gb2312.c
          +++ new/usr/src/lib/libc/port/locale/gb2312.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) 2004 Tim J. Robbins. All rights reserved.
   4    5   * Copyright (c) 2003 David Xu <davidxu@freebsd.org>
   5    6   * All rights reserved.
   6    7   *
   7    8   * Redistribution and use in source and binary forms, with or without
   8    9   * modification, are permitted provided that the following conditions
   9   10   * are met:
  10   11   * 1. Redistributions of source code must retain the above copyright
  11   12   *    notice, this list of conditions and the following disclaimer.
↓ open down ↓ 15 lines elided ↑ open up ↑
  27   28   */
  28   29  
  29   30  #include "lint.h"
  30   31  #include <sys/types.h>
  31   32  #include <errno.h>
  32   33  #include "runetype.h"
  33   34  #include <stdlib.h>
  34   35  #include <string.h>
  35   36  #include <wchar.h>
  36   37  #include "mblocal.h"
       38 +#include "lctype.h"
  37   39  
  38   40  static size_t   _GB2312_mbrtowc(wchar_t *_RESTRICT_KYWD,
  39   41                      const char *_RESTRICT_KYWD,
  40   42                      size_t, mbstate_t *_RESTRICT_KYWD);
  41   43  static int      _GB2312_mbsinit(const mbstate_t *);
  42   44  static size_t   _GB2312_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
  43   45                      mbstate_t *_RESTRICT_KYWD);
       46 +static size_t   _GB2312_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
       47 +                    const char **_RESTRICT_KYWD, size_t, size_t,
       48 +                    mbstate_t *_RESTRICT_KYWD);
       49 +static size_t   _GB2312_wcsnrtombs(char *_RESTRICT_KYWD,
       50 +                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
       51 +                    mbstate_t *_RESTRICT_KYWD);
  44   52  
       53 +
  45   54  typedef struct {
  46   55          int     count;
  47   56          uchar_t bytes[2];
  48   57  } _GB2312State;
  49   58  
  50      -int
  51      -_GB2312_init(_RuneLocale *rl)
       59 +void
       60 +_GB2312_init(struct lc_ctype *lct)
  52   61  {
  53   62  
  54      -        _CurrentRuneLocale = rl;
  55      -        __mbrtowc = _GB2312_mbrtowc;
  56      -        __wcrtomb = _GB2312_wcrtomb;
  57      -        __mbsinit = _GB2312_mbsinit;
  58      -        __ctype[520] = 2;
  59      -        charset_is_ascii = 0;
  60      -        return (0);
       63 +        lct->lc_mbrtowc = _GB2312_mbrtowc;
       64 +        lct->lc_wcrtomb = _GB2312_wcrtomb;
       65 +        lct->lc_mbsinit = _GB2312_mbsinit;
       66 +        lct->lc_mbsnrtowcs = _GB2312_mbsnrtowcs;
       67 +        lct->lc_wcsnrtombs = _GB2312_wcsnrtombs;
       68 +        lct->lc_max_mblen = 2;
       69 +        lct->lc_is_ascii = 0;
  61   70  }
  62   71  
  63   72  static int
  64   73  _GB2312_mbsinit(const mbstate_t *ps)
  65   74  {
  66   75  
  67   76          return (ps == NULL || ((const _GB2312State *)ps)->count == 0);
  68   77  }
  69   78  
  70   79  static int
↓ open down ↓ 76 lines elided ↑ open up ↑
 147  156          if (s == NULL)
 148  157                  /* Reset to initial shift state (no-op) */
 149  158                  return (1);
 150  159          if (wc & 0x8000) {
 151  160                  *s++ = (wc >> 8) & 0xff;
 152  161                  *s = wc & 0xff;
 153  162                  return (2);
 154  163          }
 155  164          *s = wc & 0xff;
 156  165          return (1);
      166 +}
      167 +
      168 +static size_t
      169 +_GB2312_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
      170 +    const char **_RESTRICT_KYWD src, size_t nms, size_t len,
      171 +    mbstate_t *_RESTRICT_KYWD ps)
      172 +{
      173 +        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _GB2312_mbrtowc));
      174 +}
      175 +
      176 +static size_t
      177 +_GB2312_wcsnrtombs(char *_RESTRICT_KYWD dst,
      178 +    const wchar_t **_RESTRICT_KYWD src, size_t nwc, size_t len,
      179 +    mbstate_t *_RESTRICT_KYWD ps)
      180 +{
      181 +        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _GB2312_wcrtomb));
 157  182  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX