about summary refs log tree commit diff
path: root/locale/duplocale.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-08-30 10:36:44 +0000
committerRoland McGrath <roland@gnu.org>2002-08-30 10:36:44 +0000
commit1ce8aaaedbf549702c607e8a944bcb06b2c37544 (patch)
tree76190020f59b42303fd7586536c5257634f6623c /locale/duplocale.c
parentccaf7306707314c44a8f636cc198a80fa7db12b1 (diff)
downloadglibc-1ce8aaaedbf549702c607e8a944bcb06b2c37544.tar.gz
glibc-1ce8aaaedbf549702c607e8a944bcb06b2c37544.tar.xz
glibc-1ce8aaaedbf549702c607e8a944bcb06b2c37544.zip
* locale/xlocale.h (struct __locale_struct): New member `__names'.
	* locale/xlocale.c (_nl_C_locobj): Update initializer.
	* locale/global-locale.c (_nl_global_locale): Likewise.
	* locale/duplocale.c (__duplocale): strdup __names elements.
	* locale/freelocale.c (__freelocale): Free __names elements.
	* locale/localename.c (_nl_current_names): Variable removed.
	(__current_locale_name): Use _NL_CURRENT_LOCALE->__names instead.
	* locale/localeinfo.h (_nl_current_names): Removed decl.
	* locale/setlocale.c: Use _nl_global_locale->__names in place of
	_nl_current_names throughout.

	* locale/setlocale.c (setlocale): strdup -> __strdup (not ISO C).

	* sysdeps/gnu/errlist-compat.awk: Emit link_warnings for sys_errlist
	and sys_nerr in the output file.

	* sunrpc/Makefile (rpcgen-cmd): Pass CPP in rpcgen's environment.
	* scripts/cpp: Just use the environment variable.

	* libio/tst-mmap-setvbuf.c (main): Use 'm' fopen flag.
	* libio/tst-mmap-offend.c (do_test): Likewise.
	* libio/tst-mmap-fflushsync.c (do_test): Likewise.
	* libio/tst-mmap-eofsync.c (do_test): Likewise.
	* libio/tst-mmap2-eofsync.c (do_test): Likewise.
Diffstat (limited to 'locale/duplocale.c')
-rw-r--r--locale/duplocale.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/locale/duplocale.c b/locale/duplocale.c
index f8e8e7299e..df856a2a83 100644
--- a/locale/duplocale.c
+++ b/locale/duplocale.c
@@ -33,15 +33,39 @@ __locale_t
 __duplocale (__locale_t dataset)
 {
   __locale_t result;
+  int cnt;
 
   /* We modify global data.  */
   __libc_lock_lock (__libc_setlocale_lock);
 
   /* Get memory.  */
   result = (__locale_t) malloc (sizeof (struct __locale_struct));
+
+  if (result != NULL)
+    /* Duplicate the names in a separate loop first so we can
+       bail out if strdup fails and not have touched usage_counts.  */
+    for (cnt = 0; cnt < __LC_LAST; ++cnt)
+      if (cnt != LC_ALL)
+	{
+	  if (dataset->__names[cnt] == _nl_C_name)
+	    result->__names[cnt] = _nl_C_name;
+	  else
+	    {
+	      result->__names[cnt] = __strdup (dataset->__names[cnt]);
+	      if (result->__names[cnt] == NULL)
+		{
+		  while (cnt-- > 0)
+		    if (dataset->__names[cnt] != _nl_C_name)
+		      free ((char *) dataset->__names[cnt]);
+		  free (result);
+		  result = NULL;
+		  break;
+		}
+	    }
+	}
+
   if (result != NULL)
     {
-      int cnt;
       for (cnt = 0; cnt < __LC_LAST; ++cnt)
 	if (cnt != LC_ALL)
 	  {