]> git.proxmox.com Git - wasi-libc.git/blobdiff - libc-top-half/musl/src/locale/locale_map.c
Update to musl 1.2.2.
[wasi-libc.git] / libc-top-half / musl / src / locale / locale_map.c
index ff9ae981cfe001ffdab32b6315edd5cfd36c6144..ebfb158f4a32fc6c25d04f609c04e4cab647a287 100644 (file)
@@ -3,9 +3,16 @@
 #ifdef __wasilibc_unmodified_upstream // WASI has no mmap
 #include <sys/mman.h>
 #endif
+#include <stdlib.h>
 #include "locale_impl.h"
 #include "libc.h"
 #include "lock.h"
+#include "fork_impl.h"
+
+#define malloc __libc_malloc
+#define calloc undef
+#define realloc undef
+#define free undef
 
 const char *__lctrans_impl(const char *msg, const struct __locale_map *lm)
 {
@@ -23,9 +30,13 @@ static const char envvars[][12] = {
        "LC_MESSAGES",
 };
 
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
+volatile int __locale_lock[1];
+volatile int *const __locale_lockptr = __locale_lock;
+#endif
+
 const struct __locale_map *__get_locale(int cat, const char *val)
 {
-       static volatile int lock[1];
        static void *volatile loc_head;
        const struct __locale_map *p;
        struct __locale_map *new = 0;
@@ -56,21 +67,13 @@ const struct __locale_map *__get_locale(int cat, const char *val)
        for (p=loc_head; p; p=p->next)
                if (!strcmp(val, p->name)) return p;
 
-       LOCK(lock);
-
-       for (p=loc_head; p; p=p->next)
-               if (!strcmp(val, p->name)) {
-                       UNLOCK(lock);
-                       return p;
-               }
-
 #ifdef __wasilibc_unmodified_upstream // WASI has no mmap, though this code could be made to use something else
        if (!libc.secure) path = getenv("MUSL_LOCPATH");
        /* FIXME: add a default path? */
 
        if (path) for (; *path; path=z+!!*z) {
                z = __strchrnul(path, ':');
-               l = z - path - !!*z;
+               l = z - path;
                if (l >= sizeof buf - n - 2) continue;
                memcpy(buf, path, l);
                buf[l] = '/';
@@ -112,6 +115,5 @@ const struct __locale_map *__get_locale(int cat, const char *val)
         * requested name was "C" or "POSIX". */
        if (!new && cat == LC_CTYPE) new = (void *)&__c_dot_utf8;
 
-       UNLOCK(lock);
        return new;
 }