X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Flocale%2Fdcngettext.c;h=8b891d0001d3da1e6550e2d71e43c3cfdd530bd8;hb=11ce1b133d594b6a454d3e8d5941e7a6a432c42b;hp=b79b70103d1a28e95919c4a6dc7b2aa32491ba4c;hpb=e4fc9ad780e36c84e1ed6b0fc01b3c53ae65ff9d;p=musl diff --git a/src/locale/dcngettext.c b/src/locale/dcngettext.c index b79b7010..8b891d00 100644 --- a/src/locale/dcngettext.c +++ b/src/locale/dcngettext.c @@ -4,10 +4,12 @@ #include #include #include +#include #include #include "locale_impl.h" -#include "libc.h" #include "atomic.h" +#include "pleval.h" +#include "lock.h" struct binding { struct binding *next; @@ -34,7 +36,7 @@ static char *gettextdir(const char *domainname, size_t *dirlen) char *bindtextdomain(const char *domainname, const char *dirname) { - static volatile int lock[2]; + static volatile int lock[1]; struct binding *p, *q; if (!domainname) return 0; @@ -98,8 +100,8 @@ struct msgcat { struct msgcat *next; const void *map; size_t map_size; - void *volatile plural_rule; - volatile int nplurals; + const char *plural_rule; + int nplurals; struct binding *binding; const struct __locale_map *lm; int cat; @@ -112,10 +114,6 @@ static char *dummy_gettextdomain() weak_alias(dummy_gettextdomain, __gettextdomain); -const unsigned char *__map_file(const char *, size_t *); -int __munmap(void *, size_t); -unsigned long __pleval(const char *, unsigned long); - char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) { static struct msgcat *volatile cats; @@ -202,20 +200,7 @@ notrans: p->lm = lm; p->map = map; p->map_size = map_size; - do { - old_cats = cats; - p->next = old_cats; - } while (a_cas_p(&cats, old_cats, p) != old_cats); - } - - const char *trans = __mo_lookup(p->map, p->map_size, msgid1); - if (!trans) goto notrans; - - /* Non-plural-processing gettext forms pass a null pointer as - * msgid2 to request that dcngettext suppress plural processing. */ - if (!msgid2) return (char *)trans; - if (!p->plural_rule) { const char *rule = "n!=1;"; unsigned long np = 2; const char *r = __mo_lookup(p->map, p->map_size, ""); @@ -239,10 +224,22 @@ notrans: rule = r+7; } } - a_store(&p->nplurals, np); - a_cas_p(&p->plural_rule, 0, (void *)rule); + p->nplurals = np; + p->plural_rule = rule; + + do { + old_cats = cats; + p->next = old_cats; + } while (a_cas_p(&cats, old_cats, p) != old_cats); } - if (p->nplurals) { + + const char *trans = __mo_lookup(p->map, p->map_size, msgid1); + if (!trans) goto notrans; + + /* Non-plural-processing gettext forms pass a null pointer as + * msgid2 to request that dcngettext suppress plural processing. */ + + if (msgid2 && p->nplurals) { unsigned long plural = __pleval(p->plural_rule, n); if (plural > p->nplurals) goto notrans; while (plural--) {