NEWLOCALE(3)

NAME
newlocale - Creates a new locale

SYNOPSIS
#include <xlocale>
locale_t
newlocale(int mask, const char * locale, locale_t base);

DESCRIPTION
Creates a new locale, inheriting some properties from an existing locale. The mask defines the components that the new locale will have set to the locale with the name specified in the locale parameter. Any other components will be inherited from base. The mask is either LC_ALL_MASK, indicating all possible locale components, or the logical OR of some combination of the following:

LC_COLLATE_MASK
    The locale for string collation routines. This controls alphabetic ordering in strcoll(3) and strxfrm(3).

LC_CTYPE_MASK
    The locale for the ctype(3) and multibyte(3) functions. This controls recognition of upper and lower case, alphabetic or non-alphabetic characters, and so on.

LC_MESSAGES_MASK
    Set a locale for message catalogs, see catopen(3) function.

LC_MONETARY_MASK
    Set a locale for formatting monetary values; this affects the localeconv(3) function.

LC_NUMERIC_MASK
    Set a locale for formatting numbers. This controls the formatting of decimal points in input and output of floating point numbers in functions such as printf(3) and scanf(3), as well as values returned by localeconv(3).

LC_TIME_MASK
    Set a locale for formatting dates and times using the strftime(3) function.
This function uses the same rules for loading locale components as setlocale(3).

RETURN VALUES
Returns a new, valid, locale_t or NULL if an error occurs. You must free the returned locale with freelocale(3).

SEE ALSO
duplocale(3), freelocale(3), localeconv(3), querylocale(3), uselocale(3), xlocale(3)

STANDARDS
NEWLOCALE(3)

This function, conforms to p1003.1-2008

NAME
newlocale, duplocale, freelocale - create and destroy locale objects

SYNOPSIS
#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);

DESCRIPTION
The function newlocale() 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 duplocale() copies oldloc, or the global locale if given the special argument LC_GLOBAL_LOCALE.

For portability, when an object returned from newlocale() or duplocale() is no longer needed, pass it to freelocale(), 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.

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

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

ERRORS
The function newlocale() fails if:

[EINVAL]
    An invalid bit is set in mask, or locname is NULL.

[ENOENT]
    Locale data is not available for locname.

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

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

STANDARDS
These functions conform to p1003.1-2008.

HISTORY
These functions have been available since OpenBSD 6.2.

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