duplocale(3) Library Functions Manual duplocale(3) duplocale - LIBRARY Standard C library (libc, -lc) #include locale_t duplocale(locale_t locobj); glibc (. feature_test_macros(7)): duplocale(): Since glibc 2.10: _XOPEN_SOURCE >= 700 Before glibc 2.10: _GNU_SOURCE duplocale() , locobj. locobj LC_GLOBAL_LOCALE, duplocale() , , setlocale(3). On success, duplocale() returns a handle for the new locale object. On error, it returns (locale_t) 0, and sets errno to indicate the error. ENOMEM . POSIX.1-2008. glibc 2.3. : o , ( newlocale(3)). o , , toupper_l(3). duplocale() , : loc = uselocale((locale_t) 0); This technique is necessary, because the above uselocale(3) call may return the value LC_GLOBAL_LOCALE, which results in undefined behavior if passed to functions such as toupper_l(3). Calling duplocale() can be used to ensure that the LC_GLOBAL_LOCALE value is converted into a usable locale object. See EXAMPLES, below. , duplocale(), freelocale(3). uselocale(3) duplocale() , toupper_l(3). , , . : $ ./a.out abc ABC #define _XOPEN_SOURCE 700 #include #include #include #include #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) int main(int argc, char *argv[]) { locale_t loc, nloc; if (argc != 2) { fprintf(stderr, "Usage: %s string\n", argv[0]); exit(EXIT_FAILURE); } /* This sequence is necessary, because uselocale() might return the value LC_GLOBAL_LOCALE, which can't be passed as an argument to toupper_l(). */ loc = uselocale((locale_t) 0); if (loc == (locale_t) 0) errExit("uselocale"); nloc = duplocale(loc); if (nloc == (locale_t) 0) errExit("duplocale"); for (char *p = argv[1]; *p; p++) putchar(toupper_l(*p, nloc)); printf("\n"); freelocale(nloc); exit(EXIT_SUCCESS); } . freelocale(3), newlocale(3), setlocale(3), uselocale(3), locale(5), locale(7) Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . duplocale(3)