Print this page
2964 need POSIX 2008 locale object support

@@ -1,10 +1,15 @@
 /*
  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
  * All rights reserved.
  *
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * under sponsorship from the FreeBSD Foundation.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.

@@ -27,10 +32,11 @@
 
 #include "lint.h"
 #include <limits.h>
 #include <stddef.h>
 #include <stdlib.h>
+
 #include "ldpart.h"
 #include "lmonetary.h"
 
 extern int __mlocale_changed;
 extern const char *__fix_locale_grouping_str(const char *);

@@ -68,22 +74,36 @@
 
 static struct lc_monetary_T _monetary_locale;
 static int      _monetary_using_locale;
 static char     *_monetary_locale_buf;
 
+struct xlocale_monetary __xlocale_global_monetary;
+
 static char
 cnv(const char *str)
 {
         int i = strtol(str, NULL, 10);
 
         if (i == -1)
                 i = CHAR_MAX;
         return ((char)i);
 }
 
-int
-__monetary_load_locale(const char *name)
+static void
+destruct_monetary(void *v)
+{
+        struct xlocale_monetary *l = v;
+
+        if (l->buffer != NULL)
+                free(l->buffer);
+
+        free(l);
+}
+
+static int
+monetary_load_locale_l(struct xlocale_monetary *loc, int *using_locale,
+    int *changed, const char *name)
 {
         int ret;
 
         ret = __part_load_locale(name, &_monetary_using_locale,
             &_monetary_locale_buf, "LC_MONETARY",

@@ -128,11 +148,37 @@
                 M_ASSIGN_ICHAR(n_sign_posn);
         }
         return (ret);
 }
 
+int
+__monetary_load_locale(const char *name)
+{
+        return (monetary_load_locale_l(&__xlocale_global_monetary,
+            &__xlocale_global_locale.using_monetary_locale,
+            &__xlocale_global_locale.monetary_locale_changed, name));
+}
+
+void *
+__monetary_load(const char *name, locale_t loc)
+{
+        struct xlocale_monetary *new;
+
+        new = calloc(sizeof(struct xlocale_monetary), 1);
+        /* XXX */
+        new->header.header.destructor = destruct_monetary;
+        if (monetary_load_locale_l(new, &loc->using_monetary_locale,
+            &loc->monetary_locale_changed, name) == _LDP_ERROR) {
+                xlocale_release(new);
+                return (NULL);
+        }
+
+        return (NULL);
+}
+
 struct lc_monetary_T *
-__get_current_monetary_locale(void)
+__get_current_monetary_locale(locale_t loc)
 {
-        return (_monetary_using_locale ? &_monetary_locale :
-            (struct lc_monetary_T *)&_C_monetary_locale);
+        return (loc->using_monetary_locale
+            ? &((struct xlocale_monetary*)loc->components[XLC_MONETARY])->locale
+            : (struct lc_monetary_T *)&_C_monetary_locale);
 }