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/none.c
          +++ new/usr/src/lib/libc/port/locale/none.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 ↓ 22 lines elided ↑ open up ↑
  34   35  
  35   36  #include "lint.h"
  36   37  #include <errno.h>
  37   38  #include <limits.h>
  38   39  #include <stddef.h>
  39   40  #include <stdio.h>
  40   41  #include <stdlib.h>
  41   42  #include <string.h>
  42   43  #include <wchar.h>
  43   44  #include <note.h>
  44      -#include "runetype.h"
  45   45  #include "mblocal.h"
       46 +#include "lctype.h"
  46   47  
  47      -static size_t   _none_mbrtowc(wchar_t *_RESTRICT_KYWD,
  48      -    const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
  49      -
  50      -static int      _none_mbsinit(const mbstate_t *);
  51      -static size_t   _none_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
  52      -    const char **_RESTRICT_KYWD src, size_t nms, size_t len,
  53      -    mbstate_t *_RESTRICT_KYWD);
  54      -static size_t   _none_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
  55      -    mbstate_t *_RESTRICT_KYWD);
  56      -static size_t   _none_wcsnrtombs(char *_RESTRICT_KYWD,
  57      -    const wchar_t **_RESTRICT_KYWD,
  58      -    size_t, size_t, mbstate_t *_RESTRICT_KYWD);
  59      -
  60   48  /* setup defaults */
  61   49  
  62      -int
  63      -_none_init(_RuneLocale *rl)
       50 +void
       51 +_none_init(struct lc_ctype *lct)
  64   52  {
  65      -        charset_is_ascii = 1;
  66      -
  67      -        __mbrtowc = _none_mbrtowc;
  68      -        __mbsinit = _none_mbsinit;
  69      -        __mbsnrtowcs = _none_mbsnrtowcs;
  70      -        __wcrtomb = _none_wcrtomb;
  71      -        __wcsnrtombs = _none_wcsnrtombs;
  72      -        _CurrentRuneLocale = rl;
  73      -        return (0);
       53 +        lct->lc_is_ascii = 1;
       54 +        lct->lc_mbrtowc = __mbrtowc_ascii;
       55 +        lct->lc_mbsinit = __mbsinit_ascii;
       56 +        lct->lc_mbsnrtowcs = __mbsnrtowcs_ascii;
       57 +        lct->lc_wcrtomb = __wcrtomb_ascii;
       58 +        lct->lc_wcsnrtombs = __wcsnrtombs_ascii;
       59 +        lct->lc_max_mblen = 1;
  74   60  }
  75   61  
  76      -static int
  77      -_none_mbsinit(const mbstate_t *unused)
       62 +int
       63 +__mbsinit_ascii(const mbstate_t *unused)
  78   64  {
  79   65          _NOTE(ARGUNUSED(unused));
  80   66  
  81   67          /*
  82   68           * Encoding is not state dependent - we are always in the
  83   69           * initial state.
  84   70           */
  85   71          return (1);
  86   72  }
  87   73  
  88      -static size_t
  89      -_none_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
       74 +size_t
       75 +__mbrtowc_ascii(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
  90   76      size_t n, mbstate_t *_RESTRICT_KYWD unused)
  91   77  {
  92   78          _NOTE(ARGUNUSED(unused));
  93   79  
  94   80          if (s == NULL)
  95   81                  /* Reset to initial shift state (no-op) */
  96   82                  return (0);
  97   83          if (n == 0)
  98   84                  /* Incomplete multibyte sequence */
  99   85                  return ((size_t)-2);
 100   86          if (pwc != NULL)
 101   87                  *pwc = (unsigned char)*s;
 102   88          return (*s == '\0' ? 0 : 1);
 103   89  }
 104   90  
 105      -static size_t
 106      -_none_wcrtomb(char *_RESTRICT_KYWD s, wchar_t wc,
       91 +size_t
       92 +__wcrtomb_ascii(char *_RESTRICT_KYWD s, wchar_t wc,
 107   93      mbstate_t *_RESTRICT_KYWD unused)
 108   94  {
 109   95          _NOTE(ARGUNUSED(unused));
 110   96  
 111   97          if (s == NULL)
 112   98                  /* Reset to initial shift state (no-op) */
 113   99                  return (1);
 114  100          if (wc < 0 || wc > UCHAR_MAX) {
 115  101                  errno = EILSEQ;
 116  102                  return ((size_t)-1);
 117  103          }
 118  104          *s = (unsigned char)wc;
 119  105          return (1);
 120  106  }
 121  107  
 122      -static size_t
 123      -_none_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
      108 +size_t
      109 +__mbsnrtowcs_ascii(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
 124  110      size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD unused)
 125  111  {
 126  112          const char *s;
 127  113          size_t nchr;
 128  114  
 129  115          _NOTE(ARGUNUSED(unused));
 130  116  
 131  117          if (dst == NULL) {
 132  118                  s = memchr(*src, '\0', nms);
 133  119                  return (s != NULL ? s - *src : nms);
↓ open down ↓ 5 lines elided ↑ open up ↑
 139  125                  if ((*dst++ = (unsigned char)*s++) == L'\0') {
 140  126                          *src = NULL;
 141  127                          return (nchr);
 142  128                  }
 143  129                  nchr++;
 144  130          }
 145  131          *src = s;
 146  132          return (nchr);
 147  133  }
 148  134  
 149      -static size_t
 150      -_none_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
      135 +size_t
      136 +__wcsnrtombs_ascii(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
 151  137      size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD unused)
 152  138  {
 153  139          const wchar_t *s;
 154  140          size_t nchr;
 155  141  
 156  142          _NOTE(ARGUNUSED(unused));
 157  143  
 158  144          if (dst == NULL) {
 159  145                  for (s = *src; nwc > 0 && *s != L'\0'; s++, nwc--) {
 160  146                          if (*s < 0 || *s > UCHAR_MAX) {
↓ open down ↓ 13 lines elided ↑ open up ↑
 174  160                  }
 175  161                  if ((*dst++ = *s++) == '\0') {
 176  162                          *src = NULL;
 177  163                          return (nchr);
 178  164                  }
 179  165                  nchr++;
 180  166          }
 181  167          *src = s;
 182  168          return (nchr);
 183  169  }
 184      -
 185      -/* setup defaults */
 186      -
 187      -size_t (*__mbrtowc)(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
 188      -    size_t, mbstate_t *_RESTRICT_KYWD) = _none_mbrtowc;
 189      -
 190      -int (*__mbsinit)(const mbstate_t *) = _none_mbsinit;
 191      -
 192      -size_t (*__mbsnrtowcs)(wchar_t *_RESTRICT_KYWD, const char **_RESTRICT_KYWD,
 193      -    size_t, size_t, mbstate_t *_RESTRICT_KYWD) = _none_mbsnrtowcs;
 194      -
 195      -size_t (*__wcrtomb)(char *_RESTRICT_KYWD, wchar_t, mbstate_t *_RESTRICT_KYWD) =
 196      -    _none_wcrtomb;
 197      -
 198      -size_t (*__wcsnrtombs)(char *_RESTRICT_KYWD, const wchar_t **_RESTRICT_KYWD,
 199      -    size_t, size_t, mbstate_t *_RESTRICT_KYWD) = _none_wcsnrtombs;
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX