---- setrunelocale.c.orig 2004-11-25 11:38:19.000000000 -0800
-+++ setrunelocale.c 2005-02-17 10:00:02.000000000 -0800
+--- setrunelocale.c.orig 2007-02-13 00:16:13.000000000 -0800
++++ setrunelocale.c 2007-02-13 00:22:39.000000000 -0800
@@ -37,6 +37,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.44 2004/10/18 02:06:18 ache Exp $");
#include <runetype.h>
#include <errno.h>
#include <limits.h>
-@@ -49,50 +51,43 @@
+@@ -49,67 +51,67 @@
#include "mblocal.h"
#include "setlocale.h"
+extern int _UTF2_init(struct __xlocale_st_runelocale *); /* deprecated */
+extern struct __xlocale_st_runelocale *_Read_RuneMagi(FILE *);
+
++extern void spin_lock(int *);
++extern void spin_unlock(int *);
++
+/* depreciated interfaces */
+rune_t sgetrune(const char *, size_t, char const **);
+int sputrune(rune_t, char *, size_t, char **);
- mbstate_t * __restrict);
+ static struct __xlocale_st_runelocale *CachedRuneLocale;
+ extern int __mb_cur_max;
++ static int cache_lock = 0;
/*
* The "C" and "POSIX" locale are always here.
return (0);
}
-@@ -100,14 +95,14 @@
+ /*
* If the locale name is the same as our cache, use the cache.
*/
++ spin_lock(&cache_lock);
if (CachedRuneLocale != NULL &&
- strcmp(encoding, ctype_encoding) == 0) {
- _CurrentRuneLocale = CachedRuneLocale;
+ _CurrentRuneLocale = &loc->__lc_ctype->_CurrentRuneLocale;
+ __mb_cur_max = loc->__lc_ctype->__mb_cur_max;
+ }
++ spin_unlock(&cache_lock);
return (0);
}
++ spin_unlock(&cache_lock);
-@@ -124,63 +119,72 @@
+ /*
+ * Slurp the locale file into the cache.
+@@ -124,63 +126,74 @@
if ((fp = fopen(name, "r")) == NULL)
return (errno == 0 ? ENOENT : errno);
- Cached__wcrtomb = __wcrtomb;
- Cached__wcsnrtombs = __wcsnrtombs;
- (void)strcpy(ctype_encoding, encoding);
++ spin_lock(&cache_lock);
+ XL_RELEASE(CachedRuneLocale);
+ CachedRuneLocale = xrl;
+ XL_RETAIN(CachedRuneLocale);
++ spin_unlock(&cache_lock);
} else
- free(rl);
+ XL_RELEASE(xrl);