Print this page
2964 need POSIX 2008 locale object support

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/timelocal.c
          +++ new/usr/src/lib/libc/port/locale/timelocal.c
↓ open down ↓ 27 lines elided ↑ open up ↑
  28   28  
  29   29  #include "lint.h"
  30   30  #include <stddef.h>
  31   31  #include "ldpart.h"
  32   32  #include "timelocal.h"
  33   33  
  34   34  static struct lc_time_T _time_locale;
  35   35  static int _time_using_locale;
  36   36  static char *time_locale_buf;
  37   37  
       38 +struct xlocale_time __xlocale_global_time;
       39 +
  38   40  #define LCTIME_SIZE (sizeof (struct lc_time_T) / sizeof (char *))
  39   41  
  40   42  static const struct lc_time_T   _C_time_locale = {
  41   43          {
  42   44                  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  43   45                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  44   46          }, {
  45   47                  "January", "February", "March", "April", "May", "June",
  46   48                  "July", "August", "September", "October", "November", "December"
  47   49          }, {
↓ open down ↓ 29 lines elided ↑ open up ↑
  77   79  
  78   80          /* date_fmt */
  79   81          "%a %b %e %H:%M:%S %Z %Y",
  80   82  
  81   83          /*
  82   84           * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
  83   85           */
  84   86          "%I:%M:%S %p"
  85   87  };
  86   88  
       89 +static void
       90 +destruct_time(void *v)
       91 +{
       92 +        struct xlocale_time *l = v;
       93 +
       94 +        if (l->buffer != NULL)
       95 +                free(l->buffer);
       96 +
       97 +        free(l);
       98 +}
       99 +
  87  100  struct lc_time_T *
  88      -__get_current_time_locale(void)
      101 +__get_current_time_locale(locale_t loc)
  89  102  {
  90      -        return (_time_using_locale ? &_time_locale :
  91      -            (struct lc_time_T *)&_C_time_locale);
      103 +        return (loc->using_time_locale
      104 +            ? &((struct xlocale_time *)loc->components[XLC_TIME])->locale
      105 +            : (struct lc_time_T *)&_C_time_locale);
      106 +}
      107 +
      108 +static int
      109 +time_load_locale(struct xlocale_time *l, int *using_locale, const char *name)
      110 +{
      111 +        struct lc_time_T *time_locale = &l->locale;
      112 +
      113 +        return (__part_load_locale(name, using_locale,
      114 +            &l->buffer, "LC_TIME",
      115 +            LCTIME_SIZE, LCTIME_SIZE,
      116 +            (const char **)time_locale));
  92  117  }
  93  118  
  94  119  int
  95  120  __time_load_locale(const char *name)
  96  121  {
  97      -        return (__part_load_locale(name, &_time_using_locale,
  98      -            &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE,
  99      -            (const char **)&_time_locale));
      122 +        return (time_load_locale(&__xlocale_global_time,
      123 +            &__xlocale_global_locale.using_time_locale, name));
      124 +}
      125 +
      126 +void *
      127 +__time_load(const char* name, locale_t loc)
      128 +{
      129 +        struct xlocale_time *new;
      130 +
      131 +        new = calloc(sizeof(struct xlocale_time), 1);
      132 +        if (new == NULL)
      133 +                return (NULL);
      134 +
      135 +        new->header.header.destructor = destruct_time;
      136 +        if (time_load_locale(new, &loc->using_time_locale, name) ==
      137 +            _LDP_ERROR) {
      138 +                xlocale_release(new);
      139 +                return (NULL);
      140 +        }
      141 +
      142 +        return (new);
 100  143  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX