]> git.saurik.com Git - apple/libc.git/blobdiff - locale/setlocale-fbsd.c
Libc-763.13.tar.gz
[apple/libc.git] / locale / setlocale-fbsd.c
index be6a7f26fe9cee43501797a3fd210b9cdc538291..9729e54426733f6ed3585645345e581afe9d73ce 100644 (file)
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -39,7 +35,7 @@
 static char sccsid[] = "@(#)setlocale.c        8.1 (Berkeley) 7/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.51 2007/01/09 00:28:00 imp Exp $");
 
 #include "xlocale_private.h"
 
@@ -103,6 +99,8 @@ static char  *currentlocale(void);
 static char    *loadlocale(int);
 __private_extern__ const char *__get_locale_env(int);
 
+#define        UNLOCK_AND_RETURN(x)    {XL_UNLOCK(&__global_locale); return (x);}
+
 char *
 setlocale(category, locale)
        int category;
@@ -121,6 +119,7 @@ setlocale(category, locale)
                return (category != LC_ALL ?
                    current_categories[category] : currentlocale());
 
+       XL_LOCK(&__global_locale);
        /*
         * Default to the current locale for everything.
         */
@@ -136,7 +135,7 @@ setlocale(category, locale)
                                env = __get_locale_env(i);
                                if (strlen(env) > ENCODING_LEN) {
                                        errno = EINVAL;
-                                       return (NULL);
+                                       UNLOCK_AND_RETURN (NULL);
                                }
                                (void)strcpy(new_categories[i], env);
                        }
@@ -144,21 +143,21 @@ setlocale(category, locale)
                        env = __get_locale_env(category);
                        if (strlen(env) > ENCODING_LEN) {
                                errno = EINVAL;
-                               return (NULL);
+                               UNLOCK_AND_RETURN (NULL);
                        }
                        (void)strcpy(new_categories[category], env);
                }
        } else if (category != LC_ALL) {
                if (strlen(locale) > ENCODING_LEN) {
                        errno = EINVAL;
-                       return (NULL);
+                       UNLOCK_AND_RETURN (NULL);
                }
                (void)strcpy(new_categories[category], locale);
        } else {
                if ((r = strchr(locale, '/')) == NULL) {
                        if (strlen(locale) > ENCODING_LEN) {
                                errno = EINVAL;
-                               return (NULL);
+                               UNLOCK_AND_RETURN (NULL);
                        }
                        for (i = 1; i < _LC_LAST; ++i)
                                (void)strcpy(new_categories[i], locale);
@@ -167,14 +166,14 @@ setlocale(category, locale)
                                ;
                        if (!r[1]) {
                                errno = EINVAL;
-                               return (NULL);  /* Hmm, just slashes... */
+                               UNLOCK_AND_RETURN (NULL);       /* Hmm, just slashes... */
                        }
                        do {
                                if (i == _LC_LAST)
                                        break;  /* Too many slashes... */
                                if ((len = r - locale) > ENCODING_LEN) {
                                        errno = EINVAL;
-                                       return (NULL);
+                                       UNLOCK_AND_RETURN (NULL);
                                }
                                (void)strlcpy(new_categories[i], locale,
                                              len + 1);
@@ -194,7 +193,7 @@ setlocale(category, locale)
        }
 
        if (category != LC_ALL)
-               return (loadlocale(category));
+               UNLOCK_AND_RETURN (loadlocale(category));
 
        save__numeric_fp_cvt = __global_locale.__numeric_fp_cvt;
        save__lc_numeric_loc = __global_locale.__lc_numeric_loc;
@@ -215,11 +214,11 @@ setlocale(category, locale)
                        __global_locale.__lc_numeric_loc = save__lc_numeric_loc;
                        XL_RELEASE(save__lc_numeric_loc);
                        errno = saverr;
-                       return (NULL);
+                       UNLOCK_AND_RETURN (NULL);
                }
        }
        XL_RELEASE(save__lc_numeric_loc);
-       return (currentlocale());
+       UNLOCK_AND_RETURN (currentlocale());
 }
 
 static char *