1 #include <libintl.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <limits.h>
6
7 static char *current_domain;
8
__gettextdomain()9 char *__gettextdomain()
10 {
11 return current_domain ? current_domain : "messages";
12 }
13
textdomain(const char * domainname)14 char *textdomain(const char *domainname)
15 {
16 if (!domainname) return __gettextdomain();
17
18 size_t domlen = strlen(domainname);
19 if (domlen > NAME_MAX) {
20 errno = EINVAL;
21 return 0;
22 }
23
24 if (!current_domain) {
25 current_domain = malloc(NAME_MAX+1);
26 if (!current_domain) return 0;
27 }
28
29 memcpy(current_domain, domainname, domlen+1);
30
31 return current_domain;
32 }
33
gettext(const char * msgid)34 char *gettext(const char *msgid)
35 {
36 return dgettext(0, msgid);
37 }
38
ngettext(const char * msgid1,const char * msgid2,unsigned long int n)39 char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n)
40 {
41 return dngettext(0, msgid1, msgid2, n);
42 }
43