Print this page
2964 need POSIX 2008 locale object support

@@ -2,10 +2,15 @@
  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
  * Copyright (c) 1991, 1993
  *      The Regents of the University of California.  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.

@@ -45,29 +50,28 @@
  * Because localeconv() may be called many times (especially by library
  * routines like printf() & strtod()), the approprate members of the
  * lconv structure are computed only when the monetary or numeric
  * locale has been changed.
  */
-int __mlocale_changed = 1;
-int __nlocale_changed = 1;
 
 /*
  * Return the current locale conversion.
  */
 struct lconv *
-localeconv(void)
+localeconv_l(locale_t loc)
 {
-        static struct lconv ret;
+        FIX_LOCALE(loc);
+        struct lconv *ret = &loc->lconv;
 
-        if (__mlocale_changed) {
+        if (loc->monetary_locale_changed) {
                 /* LC_MONETARY part */
                 struct lc_monetary_T *mptr;
 
-#define M_ASSIGN_STR(NAME) (ret.NAME = (char *)mptr->NAME)
-#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0])
+#define M_ASSIGN_STR(NAME) (ret->NAME = (char *)mptr->NAME)
+#define M_ASSIGN_CHAR(NAME) (ret->NAME = mptr->NAME[0])
 
-                mptr = __get_current_monetary_locale();
+                mptr = __get_current_monetary_locale(loc);
                 M_ASSIGN_STR(int_curr_symbol);
                 M_ASSIGN_STR(currency_symbol);
                 M_ASSIGN_STR(mon_decimal_point);
                 M_ASSIGN_STR(mon_thousands_sep);
                 M_ASSIGN_STR(mon_grouping);

@@ -85,23 +89,29 @@
                 M_ASSIGN_CHAR(int_n_cs_precedes);
                 M_ASSIGN_CHAR(int_p_sep_by_space);
                 M_ASSIGN_CHAR(int_n_sep_by_space);
                 M_ASSIGN_CHAR(int_p_sign_posn);
                 M_ASSIGN_CHAR(int_n_sign_posn);
-                __mlocale_changed = 0;
+                loc->monetary_locale_changed = 0;
         }
 
-        if (__nlocale_changed) {
+        if (loc->numeric_locale_changed) {
                 /* LC_NUMERIC part */
                 struct lc_numeric_T *nptr;
 
-#define N_ASSIGN_STR(NAME) (ret.NAME = (char *)nptr->NAME)
+#define N_ASSIGN_STR(NAME) (ret->NAME = (char *)nptr->NAME)
 
-                nptr = __get_current_numeric_locale();
+                nptr = __get_current_numeric_locale(loc);
                 N_ASSIGN_STR(decimal_point);
                 N_ASSIGN_STR(thousands_sep);
                 N_ASSIGN_STR(grouping);
-                __nlocale_changed = 0;
+                loc->numeric_locale_changed = 0;
         }
 
-        return (&ret);
+        return (ret);
+}
+
+struct lconv *
+localeconv(void)
+{
+        return (localeconv_l(__get_locale()));
 }