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

@@ -1,6 +1,7 @@
 /*
+ * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
  * Copyright (c) 1997 FreeBSD Inc.
  * All rights reserved.
  *

@@ -26,20 +27,18 @@
  * SUCH DAMAGE.
  */
 
 #include "lint.h"
 #include <stddef.h>
+#include <errno.h>
 #include "ldpart.h"
 #include "timelocal.h"
+#include "localeimpl.h"
 
-static struct lc_time_T _time_locale;
-static int _time_using_locale;
-static char *time_locale_buf;
+#define LCTIME_SIZE (sizeof (struct lc_time) / sizeof (char *))
 
-#define LCTIME_SIZE (sizeof (struct lc_time_T) / sizeof (char *))
-
-static const struct lc_time_T   _C_time_locale = {
+struct lc_time lc_time_posix = {
         {
                 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
         }, {
                 "January", "February", "March", "April", "May", "June",

@@ -82,19 +81,35 @@
          * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
          */
         "%I:%M:%S %p"
 };
 
-struct lc_time_T *
-__get_current_time_locale(void)
-{
-        return (_time_using_locale ? &_time_locale :
-            (struct lc_time_T *)&_C_time_locale);
-}
+struct locdata __posix_time_locdata = {
+        .l_lname = "C",
+        .l_refcnt = (uint32_t)-1,
+        .l_data = { &lc_time_posix }
+};
 
-int
-__time_load_locale(const char *name)
+struct locdata *
+__lc_time_load(const char *name)
 {
-        return (__part_load_locale(name, &_time_using_locale,
-            &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE,
-            (const char **)&_time_locale));
+        struct locdata  *ldata;
+        struct lc_time  *ltime;
+        int ret;
+
+        if ((ldata = __locdata_alloc(name, sizeof (*ltime))) == NULL) {
+                errno = EINVAL;
+                return (NULL);
+        }
+        ltime = ldata->l_data[0];
+
+        ret = __part_load_locale(name, (char **)&ldata->l_data[1],
+            "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)ltime);
+
+        if (ret != _LDP_LOADED) {
+                __locdata_release(ldata);
+                errno = EINVAL;
+                return (NULL);
+        }
+
+        return (ldata);
 }