newlocale(3) Library Functions Manual newlocale(3) newlocale, freelocale - (libc -lc) #include locale_t newlocale(int category_mask, const char *locale, locale_t base); void freelocale(locale_t locobj); glibc ( feature_test_macros(7)): newlocale() freelocale(): glibc 2.10: _XOPEN_SOURCE >= 700 glibc 2.10: _GNU_SOURCE newlocale() . base: o base (locale_t) 0 . o base ( newlocale() duplocale(3)) . base ( base ). base newlocale() . base . base LC_GLOBAL_LOCALE ( duplocale(3)) (locale_t) 0 . category_mask . OR LC_ADDRESS_MASK LC_CTYPE_MASK LC_COLLATE_MASK LC_IDENTIFICATION_MASK LC_MEASUREMENT_MASK LC_MESSAGES_MASK LC_MONETARY_MASK LC_NUMERIC_MASK LC_NAME_MASK LC_PAPER_MASK LC_TELEPHONE_MASK LC_TIME_MASK. LC_ALL_MASK OR . category_mask locale newlocale(). category_mask ("POSIX"). locale category_mask: "POSIX" C. "C" "POSIX". "" LC_* LANG ( locale(7)). freelocale() freelocale() locobj newlocale() duplocale(3). locobj LC_GLOBAL_LOCALE . . newlocale() duplocale(3) freelocale() locale_t. newlocale() (locale_t) 0 errno . EINVAL category_mask . EINVAL locale NULL. ENOENT locale . ENOMEM . POSIX.1-2008. glibc 2.3. newlocale() freelocale(). . LC_NUMERIC newlocale(). LC_TIME . uselocale(3) : (1) . LC_NUMERIC. . (2) . LC_TIME. . LC_NUMERIC fr_FR (): $ ./a.out fr_FR; 123456,789 Fri Mar 7 00:25:08 2014 LC_NUMERIC fr_FR () LC_TIME it_IT (): $ ./a.out fr_FR it_IT; 123456,789 ven 07 mar 2014 00:26:01 CET LC_TIME ( mi_NZ ): $ LC_ALL=mi_NZ ./a.out fr_FR "" 123456,789 Te Paraire, te 07 o Poutu-te-rangi, 2014 00:38:44 CET #define _XOPEN_SOURCE 700 #include #include #include #include #include int main(int argc, char *argv[]) { char buf[100]; time_t t; size_t s; struct tm *tm; locale_t loc, nloc; if (argc < 2) { fprintf(stderr, "Usage: %s locale1 [locale2]\n", argv[0]); exit(EXIT_FAILURE); } /* Create a new locale object, taking the LC_NUMERIC settings from the locale specified in argv[1]. */ loc = newlocale(LC_NUMERIC_MASK, argv[1], (locale_t) 0); if (loc == (locale_t) 0) err(EXIT_FAILURE, "newlocale"); /* If a second command-line argument was specified, modify the locale object to take the LC_TIME settings from the locale specified in argv[2]. We assign the result of this newlocale() call to 'nloc' rather than 'loc', since in some cases, we might want to preserve 'loc' if this call fails. */ if (argc > 2) { nloc = newlocale(LC_TIME_MASK, argv[2], loc); if (nloc == (locale_t) 0) err(EXIT_FAILURE, "newlocale"); loc = nloc; } /* Apply the newly created locale to this thread. */ uselocale(loc); /* Test effect of LC_NUMERIC. */ printf("%8.3f\n", 123456.789); /* Test effect of LC_TIME. */ t = time(NULL); tm = localtime(&t); if (tm == NULL) err(EXIT_FAILURE, "time"); s = strftime(buf, sizeof(buf), "%c", tm); if (s == 0) err(EXIT_FAILURE, "strftime"); printf("%s\n", buf); /* Free the locale object. */ uselocale(LC_GLOBAL_LOCALE); /* So 'loc' is no longer in use */ freelocale(loc); exit(EXIT_SUCCESS); } locale(1), duplocale(3), setlocale(3), uselocale(3), locale(5), locale(7) 3 . . : . 6.18 8 2026 newlocale(3)