NEWLOCALE(3P)
β¨ NEWLOCALE(3P) β¨
okay bestie, we're doing newlocale from the POSIX Programmer's Manual today and honestly? it's giving "I make locale objects, that's my whole personality" π
πΈ PROLOG πΈ
real talk first: this page lives inside the POSIX Programmer's Manual. The Linux version of this interface might act different (so go check the matching Linux man page if you're on Linux, bestie), or the interface might not even be implemented on Linux at all. π no cap.
π NAME π
newlocale β create or modify a locale object π¦
β¨ SYNOPSIS β¨
#include <locale.h>
locale_t newlocale(int category_mask, const char *locale,
locale_t base);
π DESCRIPTION π
So newlocale() shall create a brand new locale object, or modify one you already have. If the base argument is (locale_t)0, then a new locale object shall be created, periodt. heads up tho: it is unspecified whether the locale object that base points to shall be modified, or freed and a new locale object created. iykyk, that's the vibe. π
The category_mask argument is the one saying which locale categories get set or modified. You build the value for category_mask by a bitwise-inclusive OR of these 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>. it's giving bitmask buffet, and we love that. π
For each category whose corresponding bit is set in category_mask, the data from the locale named by locale shall be used. Now if you're modifying an existing locale object, the data from the locale named by locale shall replace the existing data inside that locale object. And if a completely new locale object is created, then the data for all sections that category_mask did not request shall be taken from the default locale. slay. β¨
π the preset locale values π
These preset values of locale are defined for all settings of category_mask:
"POSIX"β Specifies the minimal environment for C-language translation called the POSIX locale. the bare minimum queen π"C"β Equivalent to"POSIX". literally the same thing bestie, no cap.""β Specifies an implementation-defined native environment. This corresponds to the value of the associated environment variables,LC_*andLANG; see the Base Definitions volume of POSIX.1β2017, Chapter 7, Locale and Chapter 8, Environment Variables. π
π the base rules (important!!)
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(). so like, let it go before you call, bestie. π«Ά
If the function call fails and the base argument is not (locale_t)0, the contents of base shall remain valid and unchanged. we love a fail that doesn't ruin your whole life. π
β οΈ The behavior is undefined if thebaseargument is the special locale objectLC_GLOBAL_LOCALE, or is not a valid locale object handle and is not(locale_t)0. do not do this. i am begging. π
π¦ RETURN VALUE π¦
Upon successful completion, the newlocale() function shall return a handle which the caller may use on subsequent calls to duplocale(), freelocale(), and other functions taking a locale_t argument. that handle is your new bestie, keep it safe. π
Upon failure, the newlocale() function shall return (locale_t)0 and set errno to indicate the error. π
π ERRORS π
The newlocale() function shall fail if:
ENOMEMβ There is not enough memory available to create the locale object or load the locale data. the memory said no. πEINVALβ Thecategory_maskcontains a bit that does not correspond to a valid category. that bit is not invited to the function. π«ENOENTβ For any of the categories incategory_mask, the locale data is not available. it's not there bestie, it's just not there. π
The newlocale() function may fail if:
EINVALβ Thelocaleargument is not a valid string pointer. that pointer is not pointing, fr fr.
The following sections are informative.
π EXAMPLES π
π Constructing a Locale Object from Different Locales
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;
...
π§ Freeing up a Locale Object
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);
π APPLICATION USAGE π
Handles for locale objects created 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. pick one, bestie, don't leave it hanging. π
The special locale object LC_GLOBAL_LOCALE must not be passed for the base argument, even when it was returned by the uselocale() function. even then. even. then. π«
π RATIONALE π
None. iconic of it, honestly. nothing to explain, it's just correct. π
β FUTURE DIRECTIONS β
None. the future is bright and empty, bestie. β¨
πΈ SEE ALSO πΈ
duplocale()freelocale()uselocale()
The Base Definitions volume of POSIX.1β2017, Chapter 7, Locale, Chapter 8, Environment Variables, <locale.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
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 .
and that's the whole thing, bestie π«Ά this page came to you from IEEE/The Open Group, 2017 β newlocale(3P), that's the one, that's the era. go forth and set your masks. π β¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms