Thread-local locales.
This API allows to control locale settings on a per-thread basis and is basically a copy of POSIX’s newlocale()/duplocale()/freelocale()/uselocale() API.
These functions only affects the locale settings of the C library and of the code based on C library locales. Win32 API users, you have been warned!
This API is “reasonably” thread-safe, in that it will not change the settings of any other thread than the calling thread. However, there is no “protection” against other threads calling setlocale() or similar.
Locales | Thread-local locales. |
Types | |
nacore_locale | Locale object. |
Macros | |
NACORE_LOCALE_GLOBAL | Special locale object representing the global locale. |
NACORE_LOCALE_COLLATE_MASK | Mask for the LC_COLLATE locale category. |
NACORE_LOCALE_CTYPE_MASK | Mask for the LC_CTYPE locale category. |
NACORE_LOCALE_MONETARY_MASK | Mask for the LC_MONETARY locale category. |
NACORE_LOCALE_NUMERIC_MASK | Mask for the LC_NUMERIC locale category. |
NACORE_LOCALE_TIME_MASK | Mask for the LC_TIME locale category. |
NACORE_LOCALE_ALL_MASK | Mask with bits set for all locale categories. |
Functions | |
nacore_locale_new() | Creates a new locale object or modifies an existing one. |
nacore_locale_free() | Releases the resources allocated for a locale object. |
nacore_locale_dup() | Duplicates a locale object. |
nacore_locale_use() | Sets or gets the current locale of the calling thread. |
Mask with bits set for all locale categories.
Depending on the platform, it may not be equivalent to combining all the previous masks together (e.g., on POSIX-compliant platforms it will at least also have bits set for LC_MESSAGES).
It is equivalent to LC_ALL_MASK on POSIX-compliant platforms.
_NACORE_DEF nacore_locale nacore_locale_new( int category_mask, const char * locale, nacore_locale base )
Creates a new locale object or modifies an existing one.
Locale names are platform-dependent and are the same as those accepted by setlocale().
If base is not (nacore_locale)0 and the function succeeds, referring to base later will cause undefined behavior.
The returned locale object should either be released by calling nacore_locale_free() or be used as a base locale to another nacore_locale_new() call.
Do not use NACORE_LOCALE_GLOBAL as base.
category_mask | Mask indicating which categories to be set or modified (i.e., NACORE_LOCALE_ALL_MASK or bitwise OR of other NACORE_LOCALE_*_MASK masks). On POSIX-compliant platforms LC_*_MASK combinations are allowed. |
locale | Locale name. |
base | Base locale or (nacore_locale)0 for the current locale. |
New locale object or NULL, in which case errno is set to ENOMEM if there was not enough memory or ENOENT if, for any of the categories in category_mask, the locale data is not available.
_NACORE_DEF nacore_locale nacore_locale_dup( nacore_locale locale )
Duplicates a locale object.
The returned locale object should either be released by calling nacore_locale_free() or be used as a base locale to a nacore_locale_new() call.
NACORE_LOCALE_GLOBAL can be used as locale.
locale | The locale object. |
New locale object or NULL if there was not enough memory.
_NACORE_DEF nacore_locale nacore_locale_use( nacore_locale locale )
Sets or gets the current locale of the calling thread.
If locale is not (nacore_locale)0, the specified locale is set for the calling thread. If locale is NACORE_GLOBAL_LOCALE, the thread shall use the locale determined by setlocale().
locale | The locale object or (nacore_locale)0. |
Reference to the locale object from the previous call for the calling thread or NACORE_GLOBAL_LOCALE if there was no such previous call.
Creates a new locale object or modifies an existing one.
_NACORE_DEF nacore_locale nacore_locale_new( int category_mask, const char * locale, nacore_locale base )
Releases the resources allocated for a locale object.
_NACORE_DEF void nacore_locale_free( nacore_locale locale )
Duplicates a locale object.
_NACORE_DEF nacore_locale nacore_locale_dup( nacore_locale locale )
Sets or gets the current locale of the calling thread.
_NACORE_DEF nacore_locale nacore_locale_use( nacore_locale locale )