#include <locale.h> locale_t newlocale(int category_mask, const char *locale, locale_t base);
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, or any of the implementation-defined mask values defined in <locale.h>.
For each category with the corresponding bit set in category_mask the data from the locale named by locale shall be used. In the case of modifying an existing locale object, the data from the locale named by locale shall replace 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 shall be taken from the default locale.
The following preset values of locale are defined for all settings of category_mask:
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 shall 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.
Upon failure, the newlocale() function shall return (locale_t)0 and set errno to indicate the error.
The newlocale() function may fail if:
The following sections are informative.
The following example shows the construction of a locale where the LC_CTYPE category data comes from a locale loc1 and the LC_TIME category data from a locale loc2:
#include <locale.h> ... locale_t loc, new_loc; /* Get the "loc1" data. */ loc = newlocale (LC_CTYPE_MASK, "loc1", (locale_t)0); if (loc == (locale_t) 0) abort (); /* Get the "loc2" data. */ new_loc = newlocale (LC_TIME_MASK, "loc2", loc); if (new_loc != (locale_t) 0) /* We don t abort if this fails. In this case this simply used to unchanged locale object. */ loc = new_loc; ...
The following example shows a code fragment to free a locale object created by newlocale():
#include <locale.h> ... /* Every locale object allocated with newlocale() should be * freed using freelocale(): */ locale_t loc; /* Get the locale. */ loc = newlocale (LC_CTYPE_MASK | LC_TIME_MASK, "locname", (locale_t)0); /* ... Use the locale object ... */ ... /* Free the locale object resources. */ freelocale (loc);
The special locale object LC_GLOBAL_LOCALE must not be passed for the base argument, even when returned by the uselocale() function.
The Base Definitions volume of POSIX.1-2017, Chapter 7, Locale, Chapter 8, Environment Variables, <locale.h>
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .