duplocale man page

duplocale — duplicate a locale object


#include <locale.h>

locale_t duplocale(locale_t locobj);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):


Since glibc 2.10:


Before glibc 2.10:



The duplocale() function creates a duplicate of the locale object referred to by locobj.

If locobj is LC_GLOBAL_LOCALE, duplocale() creates a locale object containing a copy of the global locale determined by setlocale(3).

Return Value

On success, duplocale() returns a handle for the new locale object. On error, it returns (locale_t) 0, and sets errno to indicate the cause of the error.



Insufficient memory to create the duplicate locale object.


The duplocale() function first appeared in version 2.3 of the GNU C library.

Conforming to



Duplicating a locale can serve the following purposes:

Each locale object created by duplocale() should be deallocated using freelocale(3).


The program below uses uselocale(3) and duplocale() to obtain a handle for the current locale which is then passed to toupper_l(3). The program takes one command-line argument, a string of characters that is converted to uppercase and displayed on standard output. An example of its use is the following:

$ ./a.out abc

Program source

#define _XOPEN_SOURCE 700
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                        } while (0)

main(int argc, char *argv[])
    locale_t loc, nloc;
    char *p;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s string\n", argv[0]);

    /* 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)

    nloc = duplocale(loc);
    if (nloc == (locale_t) 0)

    for (p = argv[1]; *p; p++)
        putchar(toupper_l(*p, nloc));




See Also

freelocale(3), newlocale(3), setlocale(3), uselocale(3), locale(5), locale(7)


This page is part of release 4.11 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.

Referenced By

isalpha(3), locale(7), newlocale(3), strfmon(3), toupper(3), towlower(3), towupper(3), uselocale(3).

2014-03-12 Linux Programmer's Manual