#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include "collate.h"
#include "lmonetary.h" /* for __monetary_load_locale() */
#include "lnumeric.h" /* for __numeric_load_locale() */
/*
* Category names for getenv()
*/
-static char *categories[_LC_LAST] = {
+static const char * const categories[_LC_LAST] = {
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
static char new_categories[_LC_LAST][ENCODING_LEN + 1];
static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
-static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
-
static char *currentlocale(void);
static char *loadlocale(int);
__private_extern__ const char *__get_locale_env(int);
{
int i;
- (void)strcpy(current_locale_string, current_categories[1]);
+ size_t bufsiz = _LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1);
+ static char *current_locale_string = NULL;
+
+ if (current_locale_string == NULL) {
+ current_locale_string = malloc(bufsiz);
+ if (current_locale_string == NULL) {
+ return NULL;
+ }
+ }
+
+ (void)strlcpy(current_locale_string, current_categories[1], bufsiz);
for (i = 2; i < _LC_LAST; ++i)
if (strcmp(current_categories[1], current_categories[i])) {
return (0);
}
+__private_extern__ int
+__open_path_locale(const char *subpath)
+{
+ char filename[PATH_MAX];
+ int fd;
+
+ strcpy(filename, _PathLocale);
+ strcat(filename, "/");
+ strcat(filename, subpath);
+ fd = _open(filename, O_RDONLY);
+ if (fd >= 0) {
+ return fd;
+ }
+
+ strcpy(filename, _PATH_LOCALE);
+ strcat(filename, "/");
+ strcat(filename, subpath);
+ fd = _open(filename, O_RDONLY);
+ if (fd >= 0) {
+ return fd;
+ }
+
+ strcpy(filename, "/usr/local/share/locale");
+ strcat(filename, "/");
+ strcat(filename, subpath);
+ return _open(filename, O_RDONLY);
+}
+