const char * getLocaleCharset (void) { const char *locale = setlocale(LC_ALL, ""); if (locale && !isPosixLocale(locale)) { /* some 8-bit locale is set, assume its charset is correct */ return nl_langinfo(CODESET); } return defaultCharset; }
char * selectTextTable (const char *directory) { char *locale = getLocaleName(); if (locale) { char name[strlen(locale) + 1]; { size_t length = strcspn(locale, ".@"); strncpy(name, locale, length); name[length] = 0; } free(locale); locale = NULL; if (isPosixLocale(name)) { name[0] = 0; } else if (!testTextTable(directory, name)) { char *delimiter = strchr(name, '_'); if (delimiter) { *delimiter = 0; if (!testTextTable(directory, name)) name[0] = 0; } } if (name[0]) { char *textTableName = strdup(name); if (textTableName) return textTableName; logMallocError(); } } return NULL; }