12 #define V(p) be32toh(*(uint32_t *)(p))
14 static nl_catd do_catopen(const char *name)
17 const unsigned char *map = __map_file(name, &size);
18 /* Size recorded in the file must match file size; otherwise
19 * the information needed to unmap the file will be lost. */
20 if (!map || V(map) != 0xff88ff89 || 20+V(map+8) != size) {
21 if(map) munmap((void *)map, size);
28 nl_catd catopen(const char *name, int oflag)
32 if (strchr(name, '/')) return do_catopen(name);
36 const char *path, *lang, *p, *z;
37 if (libc.secure || !(path = getenv("NLSPATH"))) {
41 lang = oflag ? nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)) : getenv("LANG");
43 for (p=path; *p; p=z) {
45 z = __strchrnul(p, ':');
49 if (*p!='%') v=p, l=1;
51 case 'N': v=name; l=strlen(v); break;
52 case 'L': v=lang; l=strlen(v); break;
53 case 'l': v=lang; l=strcspn(v,"_.@"); break;
55 v=__strchrnul(lang,'_');
59 case 'c': v="UTF-8"; l=5; break;
60 case '%': v="%"; l=1; break;
63 if (!v || l >= sizeof buf - i) {
69 if (!*z && (p<z || !i)) break;
73 /* Leading : or :: in NLSPATH is same as %N */
74 catd = do_catopen(i ? buf : name);
75 if (catd != (nl_catd)-1) return catd;