about summary refs log tree commit diff
path: root/locale
diff options
context:
space:
mode:
Diffstat (limited to 'locale')
-rw-r--r--locale/C-ctype.c8
-rw-r--r--locale/categories.def3
-rw-r--r--locale/setlocale.c90
3 files changed, 62 insertions, 39 deletions
diff --git a/locale/C-ctype.c b/locale/C-ctype.c
index ab7e68eb6c..6daeb1d7cd 100644
--- a/locale/C-ctype.c
+++ b/locale/C-ctype.c
@@ -42,7 +42,7 @@ const char _nl_C_LC_CTYPE_class[768] =
   /* 0xec */ "\002\000" "\002\000" "\002\000" "\002\000" "\002\000" "\002\000"
   /* 0xf2 */ "\002\000" "\002\000" "\002\000" "\002\000" "\002\000" "\002\000"
   /* 0xf8 */ "\002\000" "\002\000" "\002\000" "\002\000" "\002\000" "\002\000"
-  /* 0xfe */ "\002\000" "\002\000" "\002\000" "\002\000" "\002\000" "\002\000"
+  /* 0xfe */ "\002\000" "\000\000" "\002\000" "\002\000" "\002\000" "\002\000"
   /* 0x04 */ "\002\000" "\002\000" "\002\000" "\002\000" "\002\000" "\003\040"
   /* 0x0a */ "\002\040" "\002\040" "\002\040" "\002\040" "\002\000" "\002\000"
   /* 0x10 */ "\002\000" "\002\000" "\002\000" "\002\000" "\002\000" "\002\000"
@@ -342,11 +342,13 @@ const struct locale_data _nl_C_LC_CTYPE =
 #endif
     { string: (const char *) _nl_C_LC_CTYPE_toupper },
     { string: (const char *) _nl_C_LC_CTYPE_tolower },
-    { string: NULL },
 #if BYTE_ORDER == BIG_ENDIAN
-    { string: NULL },
+    { string: NULL }, { string: NULL },
 #endif
     { string: _nl_C_LC_CTYPE_class32 },
+#if BYTE_ORDER == LITTLE_ENDIAN
+    { string: NULL },
+#endif
     { string: (const char *) _nl_C_LC_CTYPE_names },
 #if BYTE_ORDER == BIG_ENDIAN
     { string: NULL },
diff --git a/locale/categories.def b/locale/categories.def
index 4caef24087..7c47fd4662 100644
--- a/locale/categories.def
+++ b/locale/categories.def
@@ -79,8 +79,9 @@ DEFINE_CATEGORY
   DEFINE_ELEMENT (_NL_CTYPE_TOLOWER_EB,   "ctype-tolower-eb",   std, string)
   DEFINE_ELEMENT (_NL_CTYPE_TOUPPER_EL,   "ctype-toupper-el",   std, string)
   DEFINE_ELEMENT (_NL_CTYPE_TOLOWER_EL,   "ctype-tolower-el",   std, string)
+  DEFINE_ELEMENT (_NL_CTYPE_CLASS32,      "ctype-class32",      std, string)
   DEFINE_ELEMENT (_NL_CTYPE_NAMES_EB,	  "ctype-names-eb",     std, string)
-  DEFINE_ELEMENT (_NL_CTYPE_NAMES_EL,	  "ctype-names-eb",     std, string)
+  DEFINE_ELEMENT (_NL_CTYPE_NAMES_EL,	  "ctype-names-el",     std, string)
   DEFINE_ELEMENT (_NL_CTYPE_HASH_SIZE,	  "ctype-hash-size",    std, word)
   DEFINE_ELEMENT (_NL_CTYPE_HASH_LAYERS,  "ctype-hash-layers",  std, word)
   DEFINE_ELEMENT (_NL_CTYPE_CLASS_NAMES,  "ctype-class-names",  std, string)
diff --git a/locale/setlocale.c b/locale/setlocale.c
index 8bf58da608..4eeb5b3bce 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -19,6 +19,7 @@ Boston, MA 02111-1307, USA.  */
 #include <alloca.h>
 #include <argz.h>
 #include <errno.h>
+#include <libc-lock.h>
 #include <locale.h>
 #include <stdlib.h>
 #include <string.h>
@@ -93,7 +94,7 @@ extern void postload (void);
 
 /* Define an array indexed by category of postload functions to call after
    loading and installing that category's data.  */
-void (*const _nl_category_postload[]) (void) =
+static void (*const _nl_category_postload[]) (void) =
   {
 #define DEFINE_CATEGORY(category, category_name, items, postload, b, c, d) \
     [category] = postload,
@@ -114,6 +115,9 @@ static const char *_nl_current_names[] =
   };
 
 
+/* Lock for protecting global data.  */
+__libc_lock_define_initialized (static, lock)
+
 
 /* Use this when we come along an error.  */
 #define ERROR_RETURN							      \
@@ -238,8 +242,8 @@ setlocale (int category, const char *locale)
     return (char *) _nl_current_names[category];
 
   /* We perhaps really have to load some data.  So we determine the
-     path in which to look for the data now.  But this environment
-     variable must only be used when the binary has no SUID or SGID
+     path in which to look for the data now.  The environment variable
+     `LOCPATH' must only be used when the binary has no SUID or SGID
      bit set.  */
   locale_path = NULL;
   locale_path_len = 0;
@@ -309,6 +313,9 @@ setlocale (int category, const char *locale)
 	      ERROR_RETURN;
 	}
 
+      /* Protect global data.  */
+      __libc_lock_lock (lock);
+
       /* Load the new data for each category.  */
       while (category-- > 0)
 	/* Only actually load the data if anything will use it.  */
@@ -319,25 +326,7 @@ setlocale (int category, const char *locale)
 						 &newnames[category]);
 
 	    if (newdata[category] == NULL)
-	      {
-		/* Loading this part of the locale failed.  Abort the
-		   composite load.  */
-		int save_errno;
-	      abort_composite:
-		save_errno = errno;
-
-		while (++category < LC_ALL)
-		  if (_nl_current[category] != NULL
-		      && newdata[category] != _nl_C[category])
-		    _nl_free_locale (newdata[category]);
-		  else
-		    if (_nl_current[category] == NULL
-			&& newnames[category] != _nl_C_name)
-		      free (newnames[category]);
-
-		errno = save_errno;
-		return NULL;
-	      }
+	      goto abort_composite;
 	  }
 	else
 	  {
@@ -351,17 +340,39 @@ setlocale (int category, const char *locale)
       composite = new_composite_name (LC_ALL, newnames);
       if (composite == NULL)
 	{
+	  /* Loading this part of the locale failed.  Abort the
+	     composite load.  */
+	  int save_errno;
+
 	  category = -1;
-	  goto abort_composite;
-	}
+	abort_composite:
+	  save_errno = errno;
+
+	  while (++category < LC_ALL)
+	    if (_nl_current[category] != NULL
+		&& newdata[category] != _nl_C[category])
+	      _nl_free_locale (newdata[category]);
+	    else
+	      if (_nl_current[category] == NULL
+		  && newnames[category] != _nl_C_name)
+		free (newnames[category]);
 
-      /* Now we have loaded all the new data.  Put it in place.  */
-      for (category = 0; category < LC_ALL; ++category)
+	  errno = save_errno;
+	  composite = NULL;
+	}
+      else
 	{
-	  setdata (category, newdata[category]);
-	  setname (category, newnames[category]);
+	  /* Now we have loaded all the new data.  Put it in place.  */
+	  for (category = 0; category < LC_ALL; ++category)
+	    {
+	      setdata (category, newdata[category]);
+	      setname (category, newnames[category]);
+	    }
+	  setname (LC_ALL, composite);
 	}
-      setname (LC_ALL, composite);
+
+      /* Critical section left.  */
+      __libc_lock_unlock (lock);
 
       return composite;
     }
@@ -370,6 +381,9 @@ setlocale (int category, const char *locale)
       const struct locale_data *newdata = NULL;
       char *newname = NULL;
 
+      /* Protect global data.  */
+      __libc_lock_lock (lock);
+
       if (_nl_current[category] != NULL)
 	{
 	  /* Only actually load the data if anything will use it.  */
@@ -377,7 +391,7 @@ setlocale (int category, const char *locale)
 	  newdata = _nl_find_locale (locale_path, locale_path_len, category,
 				     (char **) &newname);
 	  if (newdata == NULL)
-	    return NULL;
+	    goto abort_single;
 	}
 
       /* Create new composite name.  */
@@ -392,14 +406,20 @@ setlocale (int category, const char *locale)
 	    _nl_free_locale (newdata);
 
 	  errno = save_errno;
-	  return NULL;
+	abort_single:
+	  newname = NULL;
 	}
+      else
+	{
+	  if (_nl_current[category] != NULL)
+	    setdata (category, newdata);
 
-      if (_nl_current[category] != NULL)
-	setdata (category, newdata);
+	  setname (category, newname);
+	  setname (LC_ALL, composite);
+	}
 
-      setname (category, newname);
-      setname (LC_ALL, composite);
+      /* Critical section left.  */
+      __libc_lock_unlock (lock);
 
       return newname;
     }