Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022

newlocale (3C)


newlocale - create or modify a locale object


#include <locale.h>
locale_t newlocale(int category_mask, const char *locale, locale_t base);


The newlocale() function creates a new locale object or modifies an existing one. If the base argument is (locale_t)0, a new locale object is created. It is unspecified whether the locale object pointed to by base is modified, or freed and a new locale object created.

The category_mask argument specifies the locale categories to be set or modified. Values for category_mask shall be constructed by a bitwise-inclusive OR of the symbolic constants LC_CTYPE_MASK, LC_NUMERIC_MASK, LC_TIME_MASK, LC_COLLATE_MASK, LC_MONETARY_MASK, and LC_MESSAGES_MASK. Alternatively, the mask can be specified as LC_ALL_MASK, which is equivalent to ORing all of the preceding constants.

For each category with the corresponding bit set in category_mask the data from the locale named by locale is used. In the case of modifying an existing locale object, the data from the locale named by locale replaces the existing data within the locale object. If a completely new locale object is created, the data for all sections not requested by category_mask is taken from the default locale.

The following preset values of locale are defined for all settings of category_mask:


Specifies the minimal environment for C-language translation called the POSIX locale.


Equivalent to POSIX.


Specifies an implementation-defined native environment. This corresponds to the value of the associated environment variables, LC_* and LANG.

If the base argument is not (locale_t)0 and the newlocale() function call succeeds, the contents of base are unspecified. Applications shall ensure that they stop using base as a locale object before calling newlocale(). If the function call fails and the base argument is not (locale_t)0, the contents of base remain valid and unchanged.

The behavior is undefined if the base argument is the special locale object LC_GLOBAL_LOCALE, or is not a valid locale object handle and is not (locale_t)0.

Return Values

Upon successful completion, the newlocale() function returns a handle which the caller may use on subsequent calls to duplocale(), freelocale(), and other functions taking a locale_t argument.

Upon failure, the newlocale() function returns (locale_t)0 and set errno to indicate the error.


The newlocale() function will fail if:


There is not enough memory available to create the locale object or load the locale data.


The category_mask contains a bit that does not correspond to a valid category or the locale argument is not a valid string pointer.


For any of the categories in category_mask, the locale data is not available.


Handles for locale objects returned by the newlocale() function should either be released by a corresponding call to freelocale(), or be used as a base locale to another newlocale() call.

The special locale object LC_GLOBAL_LOCALE must not be passed for the base argument, even when returned by the uselocale() function.


See attributes(7) for descriptions of the following attributes:

Interface Stability

See Also

duplocale(3C), freelocale(3C), uselocale(3C), attributes(7), standards(7)