Print this page
2964 need POSIX 2008 locale object support

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/lmonetary.c
          +++ new/usr/src/lib/libc/port/locale/lmonetary.c
   1    1  /*
   2    2   * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3    3   * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
   4    4   * All rights reserved.
   5    5   *
        6 + * Copyright (c) 2011 The FreeBSD Foundation
        7 + * All rights reserved.
        8 + * Portions of this software were developed by David Chisnall
        9 + * under sponsorship from the FreeBSD Foundation.
       10 + *
   6   11   * Redistribution and use in source and binary forms, with or without
   7   12   * modification, are permitted provided that the following conditions
   8   13   * are met:
   9   14   * 1. Redistributions of source code must retain the above copyright
  10   15   *    notice, this list of conditions and the following disclaimer.
  11   16   * 2. Redistributions in binary form must reproduce the above copyright
  12   17   *    notice, this list of conditions and the following disclaimer in the
  13   18   *    documentation and/or other materials provided with the distribution.
  14   19   *
  15   20   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
↓ open down ↓ 6 lines elided ↑ open up ↑
  22   27   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23   28   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24   29   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25   30   * SUCH DAMAGE.
  26   31   */
  27   32  
  28   33  #include "lint.h"
  29   34  #include <limits.h>
  30   35  #include <stddef.h>
  31   36  #include <stdlib.h>
       37 +
  32   38  #include "ldpart.h"
  33   39  #include "lmonetary.h"
  34   40  
  35   41  extern int __mlocale_changed;
  36   42  extern const char *__fix_locale_grouping_str(const char *);
  37   43  
  38   44  #define LCMONETARY_SIZE_FULL (sizeof (struct lc_monetary_T) / sizeof (char *))
  39   45  #define LCMONETARY_SIZE_MIN \
  40   46          (offsetof(struct lc_monetary_T, int_p_cs_precedes) / sizeof (char *))
  41   47  
↓ open down ↓ 21 lines elided ↑ open up ↑
  63   69          numempty,       /* int_p_sep_by_space */
  64   70          numempty,       /* int_n_sep_by_space */
  65   71          numempty,       /* int_p_sign_posn */
  66   72          numempty        /* int_n_sign_posn */
  67   73  };
  68   74  
  69   75  static struct lc_monetary_T _monetary_locale;
  70   76  static int      _monetary_using_locale;
  71   77  static char     *_monetary_locale_buf;
  72   78  
       79 +struct xlocale_monetary __xlocale_global_monetary;
       80 +
  73   81  static char
  74   82  cnv(const char *str)
  75   83  {
  76   84          int i = strtol(str, NULL, 10);
  77   85  
  78   86          if (i == -1)
  79   87                  i = CHAR_MAX;
  80   88          return ((char)i);
  81   89  }
  82   90  
  83      -int
  84      -__monetary_load_locale(const char *name)
       91 +static void
       92 +destruct_monetary(void *v)
       93 +{
       94 +        struct xlocale_monetary *l = v;
       95 +
       96 +        if (l->buffer != NULL)
       97 +                free(l->buffer);
       98 +
       99 +        free(l);
      100 +}
      101 +
      102 +static int
      103 +monetary_load_locale_l(struct xlocale_monetary *loc, int *using_locale,
      104 +    int *changed, const char *name)
  85  105  {
  86  106          int ret;
  87  107  
  88  108          ret = __part_load_locale(name, &_monetary_using_locale,
  89  109              &_monetary_locale_buf, "LC_MONETARY",
  90  110              LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
  91  111              (const char **)&_monetary_locale);
  92  112          if (ret != _LDP_ERROR)
  93  113                  __mlocale_changed = 1;
  94  114          if (ret == _LDP_LOADED) {
↓ open down ↓ 28 lines elided ↑ open up ↑
 123  143                  M_ASSIGN_ICHAR(p_cs_precedes);
 124  144                  M_ASSIGN_ICHAR(n_cs_precedes);
 125  145                  M_ASSIGN_ICHAR(p_sep_by_space);
 126  146                  M_ASSIGN_ICHAR(n_sep_by_space);
 127  147                  M_ASSIGN_ICHAR(p_sign_posn);
 128  148                  M_ASSIGN_ICHAR(n_sign_posn);
 129  149          }
 130  150          return (ret);
 131  151  }
 132  152  
      153 +int
      154 +__monetary_load_locale(const char *name)
      155 +{
      156 +        return (monetary_load_locale_l(&__xlocale_global_monetary,
      157 +            &__xlocale_global_locale.using_monetary_locale,
      158 +            &__xlocale_global_locale.monetary_locale_changed, name));
      159 +}
      160 +
      161 +void *
      162 +__monetary_load(const char *name, locale_t loc)
      163 +{
      164 +        struct xlocale_monetary *new;
      165 +
      166 +        new = calloc(sizeof(struct xlocale_monetary), 1);
      167 +        /* XXX */
      168 +        new->header.header.destructor = destruct_monetary;
      169 +        if (monetary_load_locale_l(new, &loc->using_monetary_locale,
      170 +            &loc->monetary_locale_changed, name) == _LDP_ERROR) {
      171 +                xlocale_release(new);
      172 +                return (NULL);
      173 +        }
      174 +
      175 +        return (NULL);
      176 +}
      177 +
 133  178  struct lc_monetary_T *
 134      -__get_current_monetary_locale(void)
      179 +__get_current_monetary_locale(locale_t loc)
 135  180  {
 136      -        return (_monetary_using_locale ? &_monetary_locale :
 137      -            (struct lc_monetary_T *)&_C_monetary_locale);
      181 +        return (loc->using_monetary_locale
      182 +            ? &((struct xlocale_monetary*)loc->components[XLC_MONETARY])->locale
      183 +            : (struct lc_monetary_T *)&_C_monetary_locale);
 138  184  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX