77 "C",
78 "C",
79 "C",
80 "C",
81 };
82
83 /*
84 * Path to locale storage directory. See ../i18n/_loc_path.h
85 */
86 char *_PathLocale = _DFLT_LOC_PATH;
87
88 /*
89 * The locales we are going to try and load
90 */
91 static char new_categories[NUM_CATS][ENCODING_LEN + 1];
92 static char saved_categories[NUM_CATS][ENCODING_LEN + 1];
93 static char current_locale_string[NUM_CATS * (ENCODING_LEN + 1 + 1)];
94
95 static char *currentlocale(void);
96 static char *loadlocale(int);
97 static const char *__get_locale_env(int);
98
99 char *
100 setlocale(int category, const char *locale)
101 {
102 int i, j, saverr;
103 const char *env, *r;
104
105 if (category < 0 || category >= NUM_CATS) {
106 errno = EINVAL;
107 return (NULL);
108 }
109
110 if (locale == NULL)
111 return (category != LC_ALL ?
112 current_categories[category] : currentlocale());
113
114 /*
115 * Default to the current locale for everything.
116 */
117 for (i = 0; i < NUM_CATS; ++i)
288 break;
289 case LC_MESSAGES:
290 func = __messages_load_locale;
291 break;
292 default:
293 errno = EINVAL;
294 return (NULL);
295 }
296
297 if (strcmp(new, old) == 0)
298 return (old);
299
300 if (func(new) != _LDP_ERROR) {
301 (void) strcpy(old, new);
302 return (old);
303 }
304
305 return (NULL);
306 }
307
308 static const char *
309 __get_locale_env(int category)
310 {
311 const char *env;
312
313 /* 1. check LC_ALL. */
314 env = getenv(categories[LC_ALL]);
315
316 /* 2. check LC_* */
317 if (env == NULL || !*env)
318 env = getenv(categories[category]);
319
320 /* 3. check LANG */
321 if (env == NULL || !*env)
322 env = getenv("LANG");
323
324 /* 4. if none is set, fall to "C" */
325 if (env == NULL || !*env)
326 env = "C";
327
328 return (env);
329 }
|
77 "C",
78 "C",
79 "C",
80 "C",
81 };
82
83 /*
84 * Path to locale storage directory. See ../i18n/_loc_path.h
85 */
86 char *_PathLocale = _DFLT_LOC_PATH;
87
88 /*
89 * The locales we are going to try and load
90 */
91 static char new_categories[NUM_CATS][ENCODING_LEN + 1];
92 static char saved_categories[NUM_CATS][ENCODING_LEN + 1];
93 static char current_locale_string[NUM_CATS * (ENCODING_LEN + 1 + 1)];
94
95 static char *currentlocale(void);
96 static char *loadlocale(int);
97
98 char *
99 setlocale(int category, const char *locale)
100 {
101 int i, j, saverr;
102 const char *env, *r;
103
104 if (category < 0 || category >= NUM_CATS) {
105 errno = EINVAL;
106 return (NULL);
107 }
108
109 if (locale == NULL)
110 return (category != LC_ALL ?
111 current_categories[category] : currentlocale());
112
113 /*
114 * Default to the current locale for everything.
115 */
116 for (i = 0; i < NUM_CATS; ++i)
287 break;
288 case LC_MESSAGES:
289 func = __messages_load_locale;
290 break;
291 default:
292 errno = EINVAL;
293 return (NULL);
294 }
295
296 if (strcmp(new, old) == 0)
297 return (old);
298
299 if (func(new) != _LDP_ERROR) {
300 (void) strcpy(old, new);
301 return (old);
302 }
303
304 return (NULL);
305 }
306
307 const char *
308 __get_locale_env(int category)
309 {
310 const char *env;
311
312 /* 1. check LC_ALL. */
313 env = getenv(categories[LC_ALL]);
314
315 /* 2. check LC_* */
316 if (env == NULL || !*env)
317 env = getenv(categories[category]);
318
319 /* 3. check LANG */
320 if (env == NULL || !*env)
321 env = getenv("LANG");
322
323 /* 4. if none is set, fall to "C" */
324 if (env == NULL || !*env)
325 env = "C";
326
327 return (env);
328 }
329
330 /*
331 * Detect locale storage location and store its value to _PathLocale variable
332 */
333 int
334 __detect_path_locale(void)
335 {
336 /* XXX */
337
338 return (0);
339 }
|