copy-acl: enhance Solaris ACL error handling
[gnulib.git] / lib / localename.c
index 4b77c95..d2554fd 100644 (file)
@@ -1,5 +1,5 @@
 /* Determine name of the currently selected locale.
-   Copyright (C) 1995-1999, 2000-2009 Free Software Foundation, Inc.
+   Copyright (C) 1995-2010 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published
@@ -2507,7 +2507,7 @@ gl_locale_name_from_win32_LCID (LCID lcid)
 #endif
 
 
-#if defined __APPLE__ && defined __MACH__ && HAVE_USELOCALE /* MacOS X */
+#if HAVE_USELOCALE /* glibc or MacOS X */
 
 /* Simple hash set of strings.  We don't want to drag in lots of hash table
    code here.  */
@@ -2592,15 +2592,22 @@ struniq (const char *string)
 #endif
 
 
+#if defined IN_LIBINTL || HAVE_USELOCALE
+
+/* Like gl_locale_name_thread, except that the result is not in storage of
+   indefinite extent.  */
+# if !defined IN_LIBINTL
+static
+# endif
 const char *
-gl_locale_name_thread (int category, const char *categoryname)
+gl_locale_name_thread_unsafe (int category, const char *categoryname)
 {
-#if HAVE_USELOCALE
+# if HAVE_USELOCALE
   {
     locale_t thread_locale = uselocale (NULL);
     if (thread_locale != LC_GLOBAL_LOCALE)
       {
-# if __GLIBC__ >= 2
+#  if __GLIBC__ >= 2
         /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in
            glibc < 2.12.
            See <http://sourceware.org/bugzilla/show_bug.cgi?id=10968>.  */
@@ -2611,8 +2618,8 @@ gl_locale_name_thread (int category, const char *categoryname)
              nl_langinfo (_NL_LOCALE_NAME (category)).  */
           name = thread_locale->__names[category];
         return name;
-# endif
-# if defined __APPLE__ && defined __MACH__ /* MacOS X */
+#  endif
+#  if defined __APPLE__ && defined __MACH__ /* MacOS X */
         /* The locale name is found deep in an undocumented data structure.
            Since it's stored in a buffer of size 32 and newlocale() rejects
            locale names of length > 31, we can assume that it is NUL terminated
@@ -2686,33 +2693,46 @@ gl_locale_name_thread (int category, const char *categoryname)
         switch (category)
           {
           case LC_CTYPE:
-            return struniq (tlp->__lc_ctype->__ctype_encoding);
+            return tlp->__lc_ctype->__ctype_encoding;
           case LC_NUMERIC:
             return tlp->_numeric_using_locale
-                   ? struniq (tlp->__lc_numeric->_numeric_locale_buf)
+                   ? tlp->__lc_numeric->_numeric_locale_buf
                    : "C";
           case LC_TIME:
             return tlp->_time_using_locale
-                   ? struniq (tlp->__lc_time->_time_locale_buf)
+                   ? tlp->__lc_time->_time_locale_buf
                    : "C";
           case LC_COLLATE:
             return !tlp->__collate_load_error
-                   ? struniq (tlp->__lc_collate->__encoding)
+                   ? tlp->__lc_collate->__encoding
                    : "C";
           case LC_MONETARY:
             return tlp->_monetary_using_locale
-                   ? struniq (tlp->__lc_monetary->_monetary_locale_buf)
+                   ? tlp->__lc_monetary->_monetary_locale_buf
                    : "C";
           case LC_MESSAGES:
             return tlp->_messages_using_locale
-                   ? struniq (tlp->__lc_messages->_messages_locale_buf)
+                   ? tlp->__lc_messages->_messages_locale_buf
                    : "C";
           default: /* We shouldn't get here.  */
             return "";
           }
-# endif
+#  endif
       }
   }
+# endif
+  return NULL;
+}
+
+#endif
+
+const char *
+gl_locale_name_thread (int category, const char *categoryname)
+{
+#if HAVE_USELOCALE
+  const char *name = gl_locale_name_thread_unsafe (category, categoryname);
+  if (name != NULL)
+    return struniq (name);
 #endif
   return NULL;
 }