* 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.
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"
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;
return (category != LC_ALL ?
current_categories[category] : currentlocale());
+ XL_LOCK(&__global_locale);
/*
* Default to the current locale for everything.
*/
env = __get_locale_env(i);
if (strlen(env) > ENCODING_LEN) {
errno = EINVAL;
- return (NULL);
+ UNLOCK_AND_RETURN (NULL);
}
(void)strcpy(new_categories[i], env);
}
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);
;
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);
}
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;
__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 *