Esempio n. 1
0
/*
 * Retrieve sorted list of system locales (or user locales, if PATH_LOCALE
 * environment variable is set)
 */
void
init_locales_list(void)
{
	DIR *dirp;
	struct dirent *dp;
	size_t i;
	int bogus;

	/* why call this function twice ? */
	if (locales != NULL)
		return;

	/* initialize StringList */
	locales = sl_init();
	if (locales == NULL)
		err(1, "could not allocate memory");

	/* get actual locales directory name */
	if (__detect_path_locale() != 0)
		err(1, "unable to find locales storage");

	/* open locales directory */
	dirp = opendir(_PathLocale);
	if (dirp == NULL)
		err(1, "could not open directory '%s'", _PathLocale);

	/* scan directory and store its contents except "." and ".." */
	while ((dp = readdir(dirp)) != NULL) {
		if (*(dp->d_name) == '.')
			continue;		/* exclude "." and ".." */
		for (bogus = i = 0; i < NBOGUS; i++)
			if (strncmp(dp->d_name, boguslocales[i],
			    strlen(boguslocales[i])) == 0)
				bogus = 1;
		if (!bogus)
			sl_add(locales, strdup(dp->d_name));
	}
	closedir(dirp);

	/* make sure that 'POSIX' and 'C' locales are present in the list.
	 * POSIX 1003.1-2001 requires presence of 'POSIX' name only here, but
	 * we also list 'C' for constistency
	 */
	if (sl_find(locales, "POSIX") == NULL)
		sl_add(locales, "POSIX");

	if (sl_find(locales, "C") == NULL)
		sl_add(locales, "C");

	/* make output nicer, sort the list */
	qsort(locales->sl_str, locales->sl_cur, sizeof(char *), scmp);
}
Esempio n. 2
0
static void init_key(void)
{

	pthread_key_create(&locale_info_key, xlocale_release);
	pthread_setspecific(locale_info_key, (void*)42);
	if (pthread_getspecific(locale_info_key) == (void*)42) {
		pthread_setspecific(locale_info_key, 0);
	} else {
		fake_tls = 1;
	}
	/* At least one per-thread locale has now been set. */
	__has_thread_locale = 1;
	__detect_path_locale();
}