---
name: "duplocale"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/duplocale"
---

# duplocale(3)

duplicate a locale object

## NAME

duplocale - duplicate a locale object

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <locale.h>
```

**locale\_t duplocale(locale\_t** *locobj***);**

Feature Test Macro Requirements for glibc (see [**feature\_test\_macros**(7)](/feature_test_macros/7.md)):

**duplocale**():

```
    Since glibc 2.10:
        _XOPEN_SOURCE >= 700
    Before glibc 2.10:
        _GNU_SOURCE
```

## DESCRIPTION

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)](/setlocale/3.md).

## 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 error.

## ERRORS

- **ENOMEM**

  Insufficient memory to create the duplicate locale object.

## STANDARDS

POSIX.1-2008.

## HISTORY

glibc 2.3.

## NOTES

Duplicating a locale can serve the following purposes:

- •

  To create a copy of a locale object in which one of more categories are to be modified (using [**newlocale**(3)](/newlocale/3.md)).

- •

  To obtain a handle for the current locale which can used in other functions that employ a locale handle, such as [**toupper\_l**(3)](/toupper_l/3.md). This is done by applying **duplocale**() to the value returned by the following call:

-

  ```
  loc = uselocale((locale_t) 0);
  ```

-

  This technique is necessary, because the above [**uselocale**(3)](/uselocale/3.md) call may return the value **LC\_GLOBAL\_LOCALE**, which results in undefined behavior if passed to functions such as [**toupper\_l**(3)](/toupper_l/3.md). Calling **duplocale**() can be used to ensure that the **LC\_GLOBAL\_LOCALE** value is converted into a usable locale object. See EXAMPLES, below.

Each locale object created by **duplocale**() should be deallocated using [**freelocale**(3)](/freelocale/3.md).

## EXAMPLES

The program below uses [**uselocale**(3)](/uselocale/3.md) and **duplocale**() to obtain a handle for the current locale which is then passed to [**toupper\_l**(3)](/toupper_l/3.md). 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;
ABC
```

### Program source

```
#define _XOPEN_SOURCE 700
#include <ctype.h>
#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
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)
        err(EXIT_FAILURE, "uselocale");
    nloc = duplocale(loc);
    if (nloc == (locale_t) 0)
        err(EXIT_FAILURE, "duplocale");
    for (char *p = argv[1]; *p; p++)
        putchar(toupper_l(*p, nloc));
    printf("\n");
    freelocale(nloc);
    exit(EXIT_SUCCESS);
}
```

## SEE ALSO

[**freelocale**(3)](/freelocale/3.md), [**newlocale**(3)](/newlocale/3.md), [**setlocale**(3)](/setlocale/3.md), [**uselocale**(3)](/uselocale/3.md), [**locale**(5)](/locale/5.md), [**locale**(7)](/locale/7.md)
