| 1 |
/* A POSIX <locale.h>. |
| 2 |
Copyright (C) 2007-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License as |
| 6 |
published by the Free Software Foundation; either version 2.1 of the |
| 7 |
License, or (at your option) any later version. |
| 8 |
|
| 9 |
This file is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
#if __GNUC__ >= 3 |
| 18 |
@PRAGMA_SYSTEM_HEADER@ |
| 19 |
#endif |
| 20 |
@PRAGMA_COLUMNS@ |
| 21 |
|
| 22 |
#if (defined _WIN32 && !defined __CYGWIN__ && defined __need_locale_t) \ |
| 23 |
|| defined _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H |
| 24 |
|
| 25 |
/* Special invocation convention: |
| 26 |
- Inside mingw header files, |
| 27 |
- To handle Solaris header files (through Solaris 10) when combined |
| 28 |
with gettext's libintl.h. */ |
| 29 |
|
| 30 |
#@INCLUDE_NEXT@ @NEXT_LOCALE_H@ |
| 31 |
|
| 32 |
#else |
| 33 |
/* Normal invocation convention. */ |
| 34 |
|
| 35 |
#ifndef _@GUARD_PREFIX@_LOCALE_H |
| 36 |
|
| 37 |
#define _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H |
| 38 |
|
| 39 |
/* The include_next requires a split double-inclusion guard. */ |
| 40 |
#@INCLUDE_NEXT@ @NEXT_LOCALE_H@ |
| 41 |
|
| 42 |
#undef _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H |
| 43 |
|
| 44 |
#ifndef _@GUARD_PREFIX@_LOCALE_H |
| 45 |
#define _@GUARD_PREFIX@_LOCALE_H |
| 46 |
|
| 47 |
/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ |
| 48 |
#if !_GL_CONFIG_H_INCLUDED |
| 49 |
#error "Please include config.h first." |
| 50 |
#endif |
| 51 |
|
| 52 |
/* NetBSD 5.0 mis-defines NULL. */ |
| 53 |
#include <stddef.h> |
| 54 |
|
| 55 |
/* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */ |
| 56 |
#if @HAVE_XLOCALE_H@ |
| 57 |
# include <xlocale.h> |
| 58 |
#endif |
| 59 |
|
| 60 |
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
| 61 |
|
| 62 |
/* The definition of _GL_ARG_NONNULL is copied here. */ |
| 63 |
|
| 64 |
/* The definition of _GL_WARN_ON_USE is copied here. */ |
| 65 |
|
| 66 |
/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C. |
| 67 |
On systems that don't define it, use the same value as GNU libintl. */ |
| 68 |
#if !defined LC_MESSAGES |
| 69 |
# define LC_MESSAGES 1729 |
| 70 |
#endif |
| 71 |
|
| 72 |
#if !@HAVE_LOCALE_T@ |
| 73 |
# if !defined GNULIB_defined_locale_t |
| 74 |
/* The values of the POSIX-standardized LC_* macros are: |
| 75 |
|
| 76 |
LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME |
| 77 |
|
| 78 |
glibc, Solaris, 3 0 5 4 1 2 |
| 79 |
Android |
| 80 |
macOS, *BSD 1 2 6 3 4 5 |
| 81 |
native Windows 1 2 1729 3 4 5 |
| 82 |
|
| 83 |
We map these to the log2(LC_*_MASK) values, chosen to be compatible with |
| 84 |
later releases of the same operating system. */ |
| 85 |
# if defined __APPLE__ && defined __MACH__ /* macOS */ |
| 86 |
/* LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME |
| 87 |
|
| 88 |
category 1 2 6 3 4 5 |
| 89 |
log2(LC_*_MASK) 0 1 2 3 4 5 |
| 90 |
*/ |
| 91 |
# define gl_log2_lc_mask(category) ((0x2543100 >> (4 * (category))) & 0xf) |
| 92 |
# elif defined __FreeBSD__ || defined __DragonFly__ /* FreeBSD */ |
| 93 |
/* LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME |
| 94 |
|
| 95 |
category 1 2 6 3 4 5 |
| 96 |
log2(LC_*_MASK) 0 1 5 2 3 4 |
| 97 |
*/ |
| 98 |
# define gl_log2_lc_mask(category) ((category) - 1) |
| 99 |
# elif defined _WIN32 && !defined __CYGWIN__ /* native Windows */ |
| 100 |
# define gl_log2_lc_mask(category) \ |
| 101 |
((category) == LC_MESSAGES ? 0 : (category)) |
| 102 |
# else /* glibc, Solaris, Android, NetBSD, OpenBSD */ |
| 103 |
# define gl_log2_lc_mask(category) (category) |
| 104 |
# endif |
| 105 |
/* From there we map them to array indices 0..5. */ |
| 106 |
# if (gl_log2_lc_mask (LC_COLLATE) == 0 || gl_log2_lc_mask (LC_CTYPE) == 0 \ |
| 107 |
|| gl_log2_lc_mask (LC_MESSAGES) == 0) |
| 108 |
/* glibc, Solaris, Android, macOS, FreeBSD, native Windows */ |
| 109 |
# define gl_log2_lcmask_to_index(c) (c) |
| 110 |
# define gl_index_to_log2_lcmask(i) (i) |
| 111 |
# else |
| 112 |
/* NetBSD, OpenBSD */ |
| 113 |
# define gl_log2_lcmask_to_index(c) ((c) - 1) |
| 114 |
# define gl_index_to_log2_lcmask(i) ((i) + 1) |
| 115 |
# endif |
| 116 |
/* Define the LC_*_MASK macros. */ |
| 117 |
# define LC_COLLATE_MASK (1 << gl_log2_lc_mask (LC_COLLATE)) |
| 118 |
# define LC_CTYPE_MASK (1 << gl_log2_lc_mask (LC_CTYPE)) |
| 119 |
# define LC_MESSAGES_MASK (1 << gl_log2_lc_mask (LC_MESSAGES)) |
| 120 |
# define LC_MONETARY_MASK (1 << gl_log2_lc_mask (LC_MONETARY)) |
| 121 |
# define LC_NUMERIC_MASK (1 << gl_log2_lc_mask (LC_NUMERIC)) |
| 122 |
# define LC_TIME_MASK (1 << gl_log2_lc_mask (LC_TIME)) |
| 123 |
# define LC_ALL_MASK \ |
| 124 |
(LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | LC_MONETARY_MASK \ |
| 125 |
| LC_NUMERIC_MASK | LC_TIME_MASK) |
| 126 |
/* Now define the locale_t type. */ |
| 127 |
struct gl_locale_category_t |
| 128 |
{ |
| 129 |
char *name; |
| 130 |
bool is_c_locale; |
| 131 |
# if @HAVE_WINDOWS_LOCALE_T@ |
| 132 |
/* Use the native Windows '_locale_t' type. |
| 133 |
Documentation: |
| 134 |
<https://learn.microsoft.com/en-us/cpp/c-runtime-library/locale> |
| 135 |
This field is NULL if is_c_locale is true. But don't use this NULL value, |
| 136 |
since for the native Windows *_l functions a null _locale_t means to use |
| 137 |
the global locale. */ |
| 138 |
_locale_t system_locale; |
| 139 |
# endif |
| 140 |
}; |
| 141 |
struct gl_locale_t |
| 142 |
{ |
| 143 |
struct gl_locale_category_t category[6]; |
| 144 |
}; |
| 145 |
typedef struct gl_locale_t *locale_t; |
| 146 |
# define LC_GLOBAL_LOCALE ((locale_t)(-1)) |
| 147 |
# define GNULIB_defined_locale_t 1 |
| 148 |
# endif |
| 149 |
#endif |
| 150 |
|
| 151 |
/* On native Windows with MSVC, 'struct lconv' lacks the members int_p_* and |
| 152 |
int_n_*. Instead of overriding 'struct lconv', merely define these member |
| 153 |
names as macros. This avoids trouble in C++ mode. */ |
| 154 |
#if defined _MSC_VER |
| 155 |
# define int_p_cs_precedes p_cs_precedes |
| 156 |
# define int_p_sign_posn p_sign_posn |
| 157 |
# define int_p_sep_by_space p_sep_by_space |
| 158 |
# define int_n_cs_precedes n_cs_precedes |
| 159 |
# define int_n_sign_posn n_sign_posn |
| 160 |
# define int_n_sep_by_space n_sep_by_space |
| 161 |
#endif |
| 162 |
|
| 163 |
/* Bionic libc's 'struct lconv' is just a dummy. */ |
| 164 |
#if @REPLACE_STRUCT_LCONV@ |
| 165 |
# if !defined GNULIB_defined_struct_lconv |
| 166 |
# define lconv rpl_lconv |
| 167 |
struct lconv |
| 168 |
{ |
| 169 |
/* All 'char *' are actually 'const char *'. */ |
| 170 |
|
| 171 |
/* Members that depend on the LC_NUMERIC category of the locale. See |
| 172 |
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_04> */ |
| 173 |
|
| 174 |
/* Symbol used as decimal point. */ |
| 175 |
char *decimal_point; |
| 176 |
/* Symbol used to separate groups of digits to the left of the decimal |
| 177 |
point. */ |
| 178 |
char *thousands_sep; |
| 179 |
/* Definition of the size of groups of digits to the left of the decimal |
| 180 |
point. */ |
| 181 |
char *grouping; |
| 182 |
|
| 183 |
/* Members that depend on the LC_MONETARY category of the locale. See |
| 184 |
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_03> */ |
| 185 |
|
| 186 |
/* Symbol used as decimal point. */ |
| 187 |
char *mon_decimal_point; |
| 188 |
/* Symbol used to separate groups of digits to the left of the decimal |
| 189 |
point. */ |
| 190 |
char *mon_thousands_sep; |
| 191 |
/* Definition of the size of groups of digits to the left of the decimal |
| 192 |
point. */ |
| 193 |
char *mon_grouping; |
| 194 |
/* Sign used to indicate a value >= 0. */ |
| 195 |
char *positive_sign; |
| 196 |
/* Sign used to indicate a value < 0. */ |
| 197 |
char *negative_sign; |
| 198 |
|
| 199 |
/* For formatting local currency. */ |
| 200 |
/* Currency symbol (3 characters) followed by separator (1 character). */ |
| 201 |
char *currency_symbol; |
| 202 |
/* Number of digits after the decimal point. */ |
| 203 |
char frac_digits; |
| 204 |
/* For values >= 0: 1 if the currency symbol precedes the number, 0 if it |
| 205 |
comes after the number. */ |
| 206 |
char p_cs_precedes; |
| 207 |
/* For values >= 0: Position of the sign. */ |
| 208 |
char p_sign_posn; |
| 209 |
/* For values >= 0: Placement of spaces between currency symbol, sign, and |
| 210 |
number. */ |
| 211 |
char p_sep_by_space; |
| 212 |
/* For values < 0: 1 if the currency symbol precedes the number, 0 if it |
| 213 |
comes after the number. */ |
| 214 |
char n_cs_precedes; |
| 215 |
/* For values < 0: Position of the sign. */ |
| 216 |
char n_sign_posn; |
| 217 |
/* For values < 0: Placement of spaces between currency symbol, sign, and |
| 218 |
number. */ |
| 219 |
char n_sep_by_space; |
| 220 |
|
| 221 |
/* For formatting international currency. */ |
| 222 |
/* Currency symbol (3 characters) followed by separator (1 character). */ |
| 223 |
char *int_curr_symbol; |
| 224 |
/* Number of digits after the decimal point. */ |
| 225 |
char int_frac_digits; |
| 226 |
/* For values >= 0: 1 if the currency symbol precedes the number, 0 if it |
| 227 |
comes after the number. */ |
| 228 |
char int_p_cs_precedes; |
| 229 |
/* For values >= 0: Position of the sign. */ |
| 230 |
char int_p_sign_posn; |
| 231 |
/* For values >= 0: Placement of spaces between currency symbol, sign, and |
| 232 |
number. */ |
| 233 |
char int_p_sep_by_space; |
| 234 |
/* For values < 0: 1 if the currency symbol precedes the number, 0 if it |
| 235 |
comes after the number. */ |
| 236 |
char int_n_cs_precedes; |
| 237 |
/* For values < 0: Position of the sign. */ |
| 238 |
char int_n_sign_posn; |
| 239 |
/* For values < 0: Placement of spaces between currency symbol, sign, and |
| 240 |
number. */ |
| 241 |
char int_n_sep_by_space; |
| 242 |
}; |
| 243 |
# define GNULIB_defined_struct_lconv 1 |
| 244 |
# endif |
| 245 |
#endif |
| 246 |
|
| 247 |
#if @GNULIB_LOCALECONV@ |
| 248 |
# if @REPLACE_LOCALECONV@ |
| 249 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 250 |
# undef localeconv |
| 251 |
# define localeconv rpl_localeconv |
| 252 |
# endif |
| 253 |
_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void), ); |
| 254 |
_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void)); |
| 255 |
# else |
| 256 |
_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void)); |
| 257 |
# endif |
| 258 |
# if __GLIBC__ >= 2 |
| 259 |
_GL_CXXALIASWARN (localeconv); |
| 260 |
# endif |
| 261 |
#elif @REPLACE_STRUCT_LCONV@ |
| 262 |
# if !GNULIB_LOCALECONV |
| 263 |
# undef localeconv |
| 264 |
# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv |
| 265 |
# endif |
| 266 |
#elif defined GNULIB_POSIXCHECK |
| 267 |
# if HAVE_RAW_DECL_LOCALECONV |
| 268 |
_GL_WARN_ON_USE (localeconv, |
| 269 |
"localeconv returns too few information on some platforms - " |
| 270 |
"use gnulib module localeconv for portability"); |
| 271 |
# endif |
| 272 |
#endif |
| 273 |
|
| 274 |
#if @GNULIB_SETLOCALE@ |
| 275 |
# if @REPLACE_SETLOCALE@ |
| 276 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 277 |
# undef setlocale |
| 278 |
# define setlocale rpl_setlocale |
| 279 |
# define GNULIB_defined_setlocale 1 |
| 280 |
# endif |
| 281 |
_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale), ); |
| 282 |
_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale)); |
| 283 |
# else |
| 284 |
_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale)); |
| 285 |
# endif |
| 286 |
# if __GLIBC__ >= 2 |
| 287 |
_GL_CXXALIASWARN (setlocale); |
| 288 |
# endif |
| 289 |
#elif defined GNULIB_POSIXCHECK |
| 290 |
# if HAVE_RAW_DECL_SETLOCALE |
| 291 |
_GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - " |
| 292 |
"use gnulib module setlocale for portability"); |
| 293 |
# endif |
| 294 |
#endif |
| 295 |
|
| 296 |
#if @GNULIB_SETLOCALE_NULL@ |
| 297 |
/* Included here for convenience. */ |
| 298 |
# include "setlocale_null.h" |
| 299 |
#endif |
| 300 |
|
| 301 |
#if @GNULIB_NEWLOCALE@ || (@GNULIB_GETLOCALENAME_L_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_NEWLOCALE@) |
| 302 |
# if @REPLACE_NEWLOCALE@ |
| 303 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 304 |
# undef newlocale |
| 305 |
# define newlocale rpl_newlocale |
| 306 |
# define GNULIB_defined_newlocale 1 |
| 307 |
# endif |
| 308 |
_GL_FUNCDECL_RPL (newlocale, locale_t, |
| 309 |
(int category_mask, const char *name, locale_t base), |
| 310 |
_GL_ARG_NONNULL ((2))); |
| 311 |
_GL_CXXALIAS_RPL (newlocale, locale_t, |
| 312 |
(int category_mask, const char *name, locale_t base)); |
| 313 |
# else |
| 314 |
# if !@HAVE_NEWLOCALE@ |
| 315 |
_GL_FUNCDECL_SYS (newlocale, locale_t, |
| 316 |
(int category_mask, const char *name, locale_t base), |
| 317 |
_GL_ARG_NONNULL ((2))); |
| 318 |
# endif |
| 319 |
_GL_CXXALIAS_SYS (newlocale, locale_t, |
| 320 |
(int category_mask, const char *name, locale_t base)); |
| 321 |
# endif |
| 322 |
# if __GLIBC__ >= 2 |
| 323 |
_GL_CXXALIASWARN (newlocale); |
| 324 |
# endif |
| 325 |
#elif defined GNULIB_POSIXCHECK |
| 326 |
# if HAVE_RAW_DECL_NEWLOCALE |
| 327 |
_GL_WARN_ON_USE (newlocale, "newlocale is not portable"); |
| 328 |
# endif |
| 329 |
#endif |
| 330 |
|
| 331 |
#if @GNULIB_DUPLOCALE@ || (@GNULIB_GETLOCALENAME_L_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_DUPLOCALE@) |
| 332 |
# if @REPLACE_DUPLOCALE@ |
| 333 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 334 |
# undef duplocale |
| 335 |
# define duplocale rpl_duplocale |
| 336 |
# define GNULIB_defined_duplocale 1 |
| 337 |
# endif |
| 338 |
_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale), _GL_ARG_NONNULL ((1))); |
| 339 |
_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale)); |
| 340 |
# else |
| 341 |
# if !@HAVE_DUPLOCALE@ |
| 342 |
_GL_FUNCDECL_SYS (duplocale, locale_t, (locale_t locale), _GL_ARG_NONNULL ((1))); |
| 343 |
# endif |
| 344 |
_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale)); |
| 345 |
# endif |
| 346 |
# if __GLIBC__ >= 2 |
| 347 |
_GL_CXXALIASWARN (duplocale); |
| 348 |
# endif |
| 349 |
#elif defined GNULIB_POSIXCHECK |
| 350 |
# if HAVE_RAW_DECL_DUPLOCALE |
| 351 |
_GL_WARN_ON_USE (duplocale, "duplocale is unportable and buggy on some glibc systems - " |
| 352 |
"use gnulib module duplocale for portability"); |
| 353 |
# endif |
| 354 |
#endif |
| 355 |
|
| 356 |
#if @GNULIB_FREELOCALE@ || (@GNULIB_GETLOCALENAME_L_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_FREELOCALE@) |
| 357 |
# if @REPLACE_FREELOCALE@ |
| 358 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 359 |
# undef freelocale |
| 360 |
# define freelocale rpl_freelocale |
| 361 |
# define GNULIB_defined_freelocale 1 |
| 362 |
# endif |
| 363 |
_GL_FUNCDECL_RPL (freelocale, void, (locale_t locale), _GL_ARG_NONNULL ((1))); |
| 364 |
_GL_CXXALIAS_RPL (freelocale, void, (locale_t locale)); |
| 365 |
# else |
| 366 |
# if !@HAVE_FREELOCALE@ |
| 367 |
_GL_FUNCDECL_SYS (freelocale, void, (locale_t locale), _GL_ARG_NONNULL ((1))); |
| 368 |
# endif |
| 369 |
/* Need to cast, because on FreeBSD and Mac OS X 10.13, the return type is |
| 370 |
int. */ |
| 371 |
_GL_CXXALIAS_SYS_CAST (freelocale, void, (locale_t locale)); |
| 372 |
# endif |
| 373 |
# if __GLIBC__ >= 2 |
| 374 |
_GL_CXXALIASWARN (freelocale); |
| 375 |
# endif |
| 376 |
#elif defined GNULIB_POSIXCHECK |
| 377 |
# if HAVE_RAW_DECL_FREELOCALE |
| 378 |
_GL_WARN_ON_USE (freelocale, "freelocale is not portable"); |
| 379 |
# endif |
| 380 |
#endif |
| 381 |
|
| 382 |
#if @GNULIB_GETLOCALENAME_L@ |
| 383 |
# if @REPLACE_GETLOCALENAME_L@ |
| 384 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 385 |
# undef getlocalename_l |
| 386 |
# define getlocalename_l rpl_getlocalename_l |
| 387 |
# endif |
| 388 |
_GL_FUNCDECL_RPL (getlocalename_l, const char *, |
| 389 |
(int category, locale_t locale), |
| 390 |
_GL_ARG_NONNULL ((2))); |
| 391 |
_GL_CXXALIAS_RPL (getlocalename_l, const char *, |
| 392 |
(int category, locale_t locale)); |
| 393 |
# else |
| 394 |
# if !@HAVE_GETLOCALENAME_L@ |
| 395 |
_GL_FUNCDECL_SYS (getlocalename_l, const char *, |
| 396 |
(int category, locale_t locale), |
| 397 |
_GL_ARG_NONNULL ((2))); |
| 398 |
# endif |
| 399 |
_GL_CXXALIAS_SYS (getlocalename_l, const char *, |
| 400 |
(int category, locale_t locale)); |
| 401 |
# endif |
| 402 |
# if __GLIBC__ >= 2 |
| 403 |
_GL_CXXALIASWARN (getlocalename_l); |
| 404 |
# endif |
| 405 |
#elif defined GNULIB_POSIXCHECK |
| 406 |
# if HAVE_RAW_DECL_GETLOCALENAME_L |
| 407 |
_GL_WARN_ON_USE (getlocalename_l, "getlocalename_l is not portable"); |
| 408 |
# endif |
| 409 |
#endif |
| 410 |
|
| 411 |
#endif /* _@GUARD_PREFIX@_LOCALE_H */ |
| 412 |
#endif /* _@GUARD_PREFIX@_LOCALE_H */ |
| 413 |
#endif /* !(__need_locale_t || _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H) */ |