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/timelocal.c
          +++ new/usr/src/lib/libc/port/locale/timelocal.c
   1    1  /*
        2 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
   2    3   * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3    4   * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
   4    5   * Copyright (c) 1997 FreeBSD Inc.
   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 ↓ 9 lines elided ↑ open up ↑
  21   22   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22   23   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23   24   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24   25   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25   26   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26   27   * SUCH DAMAGE.
  27   28   */
  28   29  
  29   30  #include "lint.h"
  30   31  #include <stddef.h>
       32 +#include <errno.h>
  31   33  #include "ldpart.h"
  32   34  #include "timelocal.h"
       35 +#include "localeimpl.h"
  33   36  
  34      -static struct lc_time_T _time_locale;
  35      -static int _time_using_locale;
  36      -static char *time_locale_buf;
       37 +#define LCTIME_SIZE (sizeof (struct lc_time) / sizeof (char *))
  37   38  
  38      -#define LCTIME_SIZE (sizeof (struct lc_time_T) / sizeof (char *))
  39      -
  40      -static const struct lc_time_T   _C_time_locale = {
       39 +struct lc_time lc_time_posix = {
  41   40          {
  42   41                  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  43   42                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  44   43          }, {
  45   44                  "January", "February", "March", "April", "May", "June",
  46   45                  "July", "August", "September", "October", "November", "December"
  47   46          }, {
  48   47                  "Sun", "Mon", "Tue", "Wed",
  49   48                  "Thu", "Fri", "Sat"
  50   49          }, {
↓ open down ↓ 26 lines elided ↑ open up ↑
  77   76  
  78   77          /* date_fmt */
  79   78          "%a %b %e %H:%M:%S %Z %Y",
  80   79  
  81   80          /*
  82   81           * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
  83   82           */
  84   83          "%I:%M:%S %p"
  85   84  };
  86   85  
  87      -struct lc_time_T *
  88      -__get_current_time_locale(void)
  89      -{
  90      -        return (_time_using_locale ? &_time_locale :
  91      -            (struct lc_time_T *)&_C_time_locale);
  92      -}
       86 +struct locdata __posix_time_locdata = {
       87 +        .l_lname = "C",
       88 +        .l_refcnt = (uint32_t)-1,
       89 +        .l_data = { &lc_time_posix }
       90 +};
  93   91  
  94      -int
  95      -__time_load_locale(const char *name)
       92 +struct locdata *
       93 +__lc_time_load(const char *name)
  96   94  {
  97      -        return (__part_load_locale(name, &_time_using_locale,
  98      -            &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE,
  99      -            (const char **)&_time_locale));
       95 +        struct locdata  *ldata;
       96 +        struct lc_time  *ltime;
       97 +        int ret;
       98 +
       99 +        if ((ldata = __locdata_alloc(name, sizeof (*ltime))) == NULL) {
      100 +                errno = EINVAL;
      101 +                return (NULL);
      102 +        }
      103 +        ltime = ldata->l_data[0];
      104 +
      105 +        ret = __part_load_locale(name, (char **)&ldata->l_data[1],
      106 +            "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)ltime);
      107 +
      108 +        if (ret != _LDP_LOADED) {
      109 +                __locdata_release(ldata);
      110 +                errno = EINVAL;
      111 +                return (NULL);
      112 +        }
      113 +
      114 +        return (ldata);
 100  115  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX