OpenBSD manual page server

Manual Page Search Parameters

NEWLOCALE(3) Library Functions Manual NEWLOCALE(3)

newlocale, duplocale, freelocalecreate and destroy locale objects

#include <locale.h>

locale_t
newlocale(int mask, const char *locname, locale_t oldloc);

locale_t
duplocale(locale_t oldloc);

void
freelocale(locale_t oldloc);

The function () creates a new locale object for use with uselocale(3) and with many functions that accept locale_t arguments. Locale categories not contained in the mask are copied from oldloc to the new locale object, or from the "C" locale if oldloc is (locale_t)0.

On OpenBSD, locname only affects the return value if mask includes LC_CTYPE_MASK, and locname is only meaningful if it is "C" or "POSIX", if it ends with ".UTF-8", or if it is an empty string. Other locname arguments have the same effect as "C".

The function () copies oldloc, or the global locale if given the special argument LC_GLOBAL_LOCALE.

For portability, when an object returned from () or duplocale() is no longer needed, pass it to (), even though the latter has no effect on OpenBSD. The oldloc objects passed to newlocale() or freelocale() become invalid, and using them or passing them once again to freelocale() results in undefined behaviour, whereas objects passed to duplocale() remain valid and can be passed to freelocale() later on.

The functions newlocale() and duplocale() return the new locale object on success or (locale_t)0 on failure.

If locname is an empty string, newlocale inspects LC_ALL, LC_CTYPE, and LANG as described in locale(1).

The function newlocale() fails if:

[]
An invalid bit is set in mask, or locname is NULL.
[]
Locale data is not available for locname.

On other operating systems, newlocale() and duplocale() may also fail with ENOMEM.

iswalnum(3), iswctype(3), towctrans(3), towlower(3), uselocale(3), wcscasecmp(3), wctrans(3), wctype(3)

These functions conform to IEEE Std 1003.1-2008 (“POSIX.1”) including Technical Corrigendum 3.

These functions have been available since OpenBSD 6.2.

Calling newlocale() with an oldloc argument of LC_GLOBAL_LOCALE results in undefined behaviour.

June 25, 2019 OpenBSD-7.6