fix support for initialized TLS in static PIE binaries
[musl.git] / src / locale / textdomain.c
blobc501501d2b0e728f2634dcfa3458fc9101ccfab7
1 #include <libintl.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <limits.h>
6 #include "libc.h"
7 #include "atomic.h"
9 static char *current_domain;
11 char *__gettextdomain()
13 return current_domain ? current_domain : "messages";
16 char *textdomain(const char *domainname)
18 if (!domainname) return __gettextdomain();
20 size_t domlen = strlen(domainname);
21 if (domlen > NAME_MAX) {
22 errno = EINVAL;
23 return 0;
26 if (!current_domain) {
27 current_domain = malloc(NAME_MAX+1);
28 if (!current_domain) return 0;
31 memcpy(current_domain, domainname, domlen+1);
33 return current_domain;
36 char *gettext(const char *msgid)
38 return dgettext(0, msgid);
41 char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n)
43 return dngettext(0, msgid1, msgid2, n);