Deleted Added
full compact
45a46
> #include <sys/stat.h>
75a77
> static char saved_categories[_LC_LAST][32];
81a84
> static int stub_load_locale __P((const char *));
94c97
< int found, i, len;
---
> int i, j, len;
97,100c100
< if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE")))
< _PathLocale = _PATH_LOCALE;
<
< if (category < 0 || category >= _LC_LAST)
---
> if (category < LC_ALL || category >= _LC_LAST)
104c104
< return (category ?
---
> return (category != LC_ALL ?
110c110
< for (i = 1; i < _LC_LAST; ++i)
---
> for (i = 1; i < _LC_LAST; ++i) {
111a112,113
> (void)strcpy(saved_categories[i], current_categories[i]);
> }
119,120c121,122
< if (!env)
< env = getenv(categories[0]);
---
> if (category != LC_ALL && (!env || !*env))
> env = getenv(categories[LC_ALL]);
122c124
< if (!env)
---
> if (!env || !*env)
125c127
< if (!env)
---
> if (!env || !*env)
130c132
< if (!category) {
---
> if (category == LC_ALL) {
132,133c134,135
< if (!(env = getenv(categories[i])))
< env = new_categories[0];
---
> if (!(env = getenv(categories[i])) || !*env)
> env = new_categories[LC_ALL];
138c140
< } else if (category) {
---
> } else if (category != LC_ALL) {
166,167c168,176
< if (category)
< return (loadlocale(category));
---
> if (category) {
> if ((r = loadlocale(category)) == NULL) {
> (void)strcpy(new_categories[category],
> saved_categories[category]);
> /* XXX can fail too */
> (void)loadlocale(category);
> }
> return (r);
> }
169d177
< found = 0;
171,175c179,188
< if (loadlocale(i) != NULL)
< found = 1;
< if (found)
< return (currentlocale());
< return (NULL);
---
> if (loadlocale(i) == NULL) {
> for (j = 1; j < i; j++) {
> (void)strcpy(new_categories[j],
> saved_categories[j]);
> /* XXX can fail too */
> (void)loadlocale(j);
> }
> return (NULL);
> }
> return (currentlocale());
192c205
< int i, len;
---
> int i;
198,204d210
< len = strlen(current_categories[1]) + 1 +
< strlen(current_categories[2]) + 1 +
< strlen(current_categories[3]) + 1 +
< strlen(current_categories[4]) + 1 +
< strlen(current_categories[5]) + 1;
< if (len > sizeof(current_locale_string))
< return NULL;
223,226c229,231
< #if 0
< char name[PATH_MAX];
< #endif
< if (strcmp(new_categories[category],
---
> char *encoding = new_categories[category];
>
> if (strcmp(encoding,
229a235,247
> if ( !_PathLocale
> && strcmp(encoding, "C") && strcmp(encoding, "POSIX")
> ) {
> char *pl = getenv("PATH_LOCALE");
>
> if (!pl)
> _PathLocale = _PATH_LOCALE;
> else if ( strlen(pl) + 45 > PATH_MAX
> || !(_PathLocale = strdup(pl))
> )
> return (NULL);
> }
>
232c250
< if (_xpg4_setrunelocale(new_categories[LC_CTYPE]))
---
> if (_xpg4_setrunelocale(encoding))
234c252
< if (setrunelocale(new_categories[LC_CTYPE]))
---
> if (setrunelocale(encoding))
237,238c255
< (void)strcpy(current_categories[LC_CTYPE],
< new_categories[LC_CTYPE]);
---
> (void)strcpy(current_categories[LC_CTYPE], encoding);
243c260
< if (__collate_load_tables(new_categories[LC_COLLATE]) < 0)
---
> if (__collate_load_tables(encoding) < 0)
245,246c262
< (void)strcpy(current_categories[LC_COLLATE],
< new_categories[LC_COLLATE]);
---
> (void)strcpy(current_categories[LC_COLLATE], encoding);
251c267
< if (__time_load_locale(new_categories[LC_TIME]) < 0)
---
> if (__time_load_locale(encoding) < 0)
253,254c269
< (void)strcpy(current_categories[LC_TIME],
< new_categories[LC_TIME]);
---
> (void)strcpy(current_categories[LC_TIME], encoding);
258,267c273,276
< if (!strcmp(new_categories[category], "C") ||
< !strcmp(new_categories[category], "POSIX")) {
<
< /*
< * Some day this will need to reset the locale to the default
< * C locale. Since we have no way to change them as of yet,
< * there is no need to reset them.
< */
< (void)strcpy(current_categories[category],
< new_categories[category]);
---
> if (category == LC_MONETARY || category == LC_NUMERIC) {
> if (stub_load_locale(encoding))
> return (NULL);
> (void)strcpy(current_categories[category], encoding);
269a279,302
>
> /* Just in case...*/
> return (NULL);
> }
>
> static int
> stub_load_locale(encoding)
> const char *encoding;
> {
> char name[PATH_MAX];
> struct stat st;
>
> if (!encoding)
> return(1);
> /*
> * The "C" and "POSIX" locale are always here.
> */
> if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX"))
> return(0);
> if (!_PathLocale)
> return(1);
> strcpy(name, _PathLocale);
> strcat(name, "/");
> strcat(name, encoding);
274,275d306
< (void)snprintf(name, sizeof(name), "%s/%s/%s",
< _PathLocale, new_categories[category], categories[category]);
277,283c308
< switch (category) {
< case LC_MONETARY:
< case LC_NUMERIC:
< return (NULL);
< }
< /* Just in case...*/
< return (NULL);
---
> return (stat(name, &st) != 0 || !S_ISDIR(st.st_mode));