summaryrefslogtreecommitdiffstats
path: root/gl/locale.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/locale.in.h')
-rw-r--r--gl/locale.in.h195
1 files changed, 152 insertions, 43 deletions
diff --git a/gl/locale.in.h b/gl/locale.in.h
index 1b11a41c..34f8c5b6 100644
--- a/gl/locale.in.h
+++ b/gl/locale.in.h
@@ -1,5 +1,5 @@
1/* A POSIX <locale.h>. 1/* A POSIX <locale.h>.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc. 2 Copyright (C) 2007-2025 Free Software Foundation, Inc.
3 3
4 This file is free software: you can redistribute it and/or modify 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 5 it under the terms of the GNU Lesser General Public License as
@@ -20,7 +20,7 @@
20@PRAGMA_COLUMNS@ 20@PRAGMA_COLUMNS@
21 21
22#if (defined _WIN32 && !defined __CYGWIN__ && defined __need_locale_t) \ 22#if (defined _WIN32 && !defined __CYGWIN__ && defined __need_locale_t) \
23 || defined _GL_ALREADY_INCLUDING_LOCALE_H 23 || defined _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H
24 24
25/* Special invocation convention: 25/* Special invocation convention:
26 - Inside mingw header files, 26 - Inside mingw header files,
@@ -34,12 +34,12 @@
34 34
35#ifndef _@GUARD_PREFIX@_LOCALE_H 35#ifndef _@GUARD_PREFIX@_LOCALE_H
36 36
37#define _GL_ALREADY_INCLUDING_LOCALE_H 37#define _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H
38 38
39/* The include_next requires a split double-inclusion guard. */ 39/* The include_next requires a split double-inclusion guard. */
40#@INCLUDE_NEXT@ @NEXT_LOCALE_H@ 40#@INCLUDE_NEXT@ @NEXT_LOCALE_H@
41 41
42#undef _GL_ALREADY_INCLUDING_LOCALE_H 42#undef _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H
43 43
44#ifndef _@GUARD_PREFIX@_LOCALE_H 44#ifndef _@GUARD_PREFIX@_LOCALE_H
45#define _@GUARD_PREFIX@_LOCALE_H 45#define _@GUARD_PREFIX@_LOCALE_H
@@ -69,6 +69,85 @@
69# define LC_MESSAGES 1729 69# define LC_MESSAGES 1729
70#endif 70#endif
71 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. */
127struct 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};
141struct gl_locale_t
142{
143 struct gl_locale_category_t category[6];
144};
145typedef 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
72/* On native Windows with MSVC, 'struct lconv' lacks the members int_p_* and 151/* On native Windows with MSVC, 'struct lconv' lacks the members int_p_* and
73 int_n_*. Instead of overriding 'struct lconv', merely define these member 152 int_n_*. Instead of overriding 'struct lconv', merely define these member
74 names as macros. This avoids trouble in C++ mode. */ 153 names as macros. This avoids trouble in C++ mode. */
@@ -83,7 +162,8 @@
83 162
84/* Bionic libc's 'struct lconv' is just a dummy. */ 163/* Bionic libc's 'struct lconv' is just a dummy. */
85#if @REPLACE_STRUCT_LCONV@ 164#if @REPLACE_STRUCT_LCONV@
86# define lconv rpl_lconv 165# if !defined GNULIB_defined_struct_lconv
166# define lconv rpl_lconv
87struct lconv 167struct lconv
88{ 168{
89 /* All 'char *' are actually 'const char *'. */ 169 /* All 'char *' are actually 'const char *'. */
@@ -160,6 +240,8 @@ struct lconv
160 number. */ 240 number. */
161 char int_n_sep_by_space; 241 char int_n_sep_by_space;
162}; 242};
243# define GNULIB_defined_struct_lconv 1
244# endif
163#endif 245#endif
164 246
165#if @GNULIB_LOCALECONV@ 247#if @GNULIB_LOCALECONV@
@@ -168,7 +250,7 @@ struct lconv
168# undef localeconv 250# undef localeconv
169# define localeconv rpl_localeconv 251# define localeconv rpl_localeconv
170# endif 252# endif
171_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void)); 253_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void), );
172_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void)); 254_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void));
173# else 255# else
174_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void)); 256_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void));
@@ -177,8 +259,10 @@ _GL_CXXALIAS_SYS (localeconv, struct lconv *, (void));
177_GL_CXXALIASWARN (localeconv); 259_GL_CXXALIASWARN (localeconv);
178# endif 260# endif
179#elif @REPLACE_STRUCT_LCONV@ 261#elif @REPLACE_STRUCT_LCONV@
180# undef localeconv 262# if !GNULIB_LOCALECONV
181# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv 263# undef localeconv
264# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv
265# endif
182#elif defined GNULIB_POSIXCHECK 266#elif defined GNULIB_POSIXCHECK
183# undef localeconv 267# undef localeconv
184# if HAVE_RAW_DECL_LOCALECONV 268# if HAVE_RAW_DECL_LOCALECONV
@@ -195,7 +279,7 @@ _GL_WARN_ON_USE (localeconv,
195# define setlocale rpl_setlocale 279# define setlocale rpl_setlocale
196# define GNULIB_defined_setlocale 1 280# define GNULIB_defined_setlocale 1
197# endif 281# endif
198_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale)); 282_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale), );
199_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale)); 283_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale));
200# else 284# else
201_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale)); 285_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale));
@@ -216,7 +300,7 @@ _GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - "
216# include "setlocale_null.h" 300# include "setlocale_null.h"
217#endif 301#endif
218 302
219#if /*@GNULIB_NEWLOCALE@ ||*/ (@GNULIB_LOCALENAME_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_NEWLOCALE@) 303#if @GNULIB_NEWLOCALE@ || (@GNULIB_GETLOCALENAME_L_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_NEWLOCALE@)
220# if @REPLACE_NEWLOCALE@ 304# if @REPLACE_NEWLOCALE@
221# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 305# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
222# undef newlocale 306# undef newlocale
@@ -224,24 +308,22 @@ _GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - "
224# define GNULIB_defined_newlocale 1 308# define GNULIB_defined_newlocale 1
225# endif 309# endif
226_GL_FUNCDECL_RPL (newlocale, locale_t, 310_GL_FUNCDECL_RPL (newlocale, locale_t,
227 (int category_mask, const char *name, locale_t base) 311 (int category_mask, const char *name, locale_t base),
228 _GL_ARG_NONNULL ((2))); 312 _GL_ARG_NONNULL ((2)));
229_GL_CXXALIAS_RPL (newlocale, locale_t, 313_GL_CXXALIAS_RPL (newlocale, locale_t,
230 (int category_mask, const char *name, locale_t base)); 314 (int category_mask, const char *name, locale_t base));
231# else 315# else
232# if @HAVE_NEWLOCALE@ 316# if !@HAVE_NEWLOCALE@
317_GL_FUNCDECL_SYS (newlocale, locale_t,
318 (int category_mask, const char *name, locale_t base),
319 _GL_ARG_NONNULL ((2)));
320# endif
233_GL_CXXALIAS_SYS (newlocale, locale_t, 321_GL_CXXALIAS_SYS (newlocale, locale_t,
234 (int category_mask, const char *name, locale_t base)); 322 (int category_mask, const char *name, locale_t base));
235# endif
236# endif 323# endif
237# if __GLIBC__ >= 2 && @HAVE_NEWLOCALE@ 324# if __GLIBC__ >= 2
238_GL_CXXALIASWARN (newlocale); 325_GL_CXXALIASWARN (newlocale);
239# endif 326# endif
240# if @HAVE_NEWLOCALE@ || @REPLACE_NEWLOCALE@
241# ifndef HAVE_WORKING_NEWLOCALE
242# define HAVE_WORKING_NEWLOCALE 1
243# endif
244# endif
245#elif defined GNULIB_POSIXCHECK 327#elif defined GNULIB_POSIXCHECK
246# undef newlocale 328# undef newlocale
247# if HAVE_RAW_DECL_NEWLOCALE 329# if HAVE_RAW_DECL_NEWLOCALE
@@ -249,53 +331,50 @@ _GL_WARN_ON_USE (newlocale, "newlocale is not portable");
249# endif 331# endif
250#endif 332#endif
251 333
252#if @GNULIB_DUPLOCALE@ || (@GNULIB_LOCALENAME_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_DUPLOCALE@) 334#if @GNULIB_DUPLOCALE@ || (@GNULIB_GETLOCALENAME_L_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_DUPLOCALE@)
253# if @HAVE_DUPLOCALE@ /* locale_t may be undefined if !@HAVE_DUPLOCALE@. */ 335# if @REPLACE_DUPLOCALE@
254# if @REPLACE_DUPLOCALE@ 336# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
255# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 337# undef duplocale
256# undef duplocale 338# define duplocale rpl_duplocale
257# define duplocale rpl_duplocale 339# define GNULIB_defined_duplocale 1
258# define GNULIB_defined_duplocale 1 340# endif
259# endif 341_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale), _GL_ARG_NONNULL ((1)));
260_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
261_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale)); 342_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
262# else 343# else
263_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale)); 344# if !@HAVE_DUPLOCALE@
345_GL_FUNCDECL_SYS (duplocale, locale_t, (locale_t locale), _GL_ARG_NONNULL ((1)));
264# endif 346# endif
347_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
265# endif 348# endif
266# if __GLIBC__ >= 2 && @HAVE_DUPLOCALE@ 349# if __GLIBC__ >= 2
267_GL_CXXALIASWARN (duplocale); 350_GL_CXXALIASWARN (duplocale);
268# endif 351# endif
269# if @HAVE_DUPLOCALE@
270# ifndef HAVE_WORKING_DUPLOCALE
271# define HAVE_WORKING_DUPLOCALE 1
272# endif
273# endif
274#elif defined GNULIB_POSIXCHECK 352#elif defined GNULIB_POSIXCHECK
275# undef duplocale 353# undef duplocale
276# if HAVE_RAW_DECL_DUPLOCALE 354# if HAVE_RAW_DECL_DUPLOCALE
277_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - " 355_GL_WARN_ON_USE (duplocale, "duplocale is unportable and buggy on some glibc systems - "
278 "use gnulib module duplocale for portability"); 356 "use gnulib module duplocale for portability");
279# endif 357# endif
280#endif 358#endif
281 359
282#if /*@GNULIB_FREELOCALE@ ||*/ (@GNULIB_LOCALENAME_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_FREELOCALE@) 360#if @GNULIB_FREELOCALE@ || (@GNULIB_GETLOCALENAME_L_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_FREELOCALE@)
283# if @REPLACE_FREELOCALE@ 361# if @REPLACE_FREELOCALE@
284# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 362# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
285# undef freelocale 363# undef freelocale
286# define freelocale rpl_freelocale 364# define freelocale rpl_freelocale
287# define GNULIB_defined_freelocale 1 365# define GNULIB_defined_freelocale 1
288# endif 366# endif
289_GL_FUNCDECL_RPL (freelocale, void, (locale_t locale) _GL_ARG_NONNULL ((1))); 367_GL_FUNCDECL_RPL (freelocale, void, (locale_t locale), _GL_ARG_NONNULL ((1)));
290_GL_CXXALIAS_RPL (freelocale, void, (locale_t locale)); 368_GL_CXXALIAS_RPL (freelocale, void, (locale_t locale));
291# else 369# else
292# if @HAVE_FREELOCALE@ 370# if !@HAVE_FREELOCALE@
371_GL_FUNCDECL_SYS (freelocale, void, (locale_t locale), _GL_ARG_NONNULL ((1)));
372# endif
293/* Need to cast, because on FreeBSD and Mac OS X 10.13, the return type is 373/* Need to cast, because on FreeBSD and Mac OS X 10.13, the return type is
294 int. */ 374 int. */
295_GL_CXXALIAS_SYS_CAST (freelocale, void, (locale_t locale)); 375_GL_CXXALIAS_SYS_CAST (freelocale, void, (locale_t locale));
296# endif
297# endif 376# endif
298# if __GLIBC__ >= 2 && @HAVE_FREELOCALE@ 377# if __GLIBC__ >= 2
299_GL_CXXALIASWARN (freelocale); 378_GL_CXXALIASWARN (freelocale);
300# endif 379# endif
301#elif defined GNULIB_POSIXCHECK 380#elif defined GNULIB_POSIXCHECK
@@ -305,6 +384,36 @@ _GL_WARN_ON_USE (freelocale, "freelocale is not portable");
305# endif 384# endif
306#endif 385#endif
307 386
387#if @GNULIB_GETLOCALENAME_L@
388# if @REPLACE_GETLOCALENAME_L@
389# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
390# undef getlocalename_l
391# define getlocalename_l rpl_getlocalename_l
392# endif
393_GL_FUNCDECL_RPL (getlocalename_l, const char *,
394 (int category, locale_t locale),
395 _GL_ARG_NONNULL ((2)));
396_GL_CXXALIAS_RPL (getlocalename_l, const char *,
397 (int category, locale_t locale));
398# else
399# if !@HAVE_GETLOCALENAME_L@
400_GL_FUNCDECL_SYS (getlocalename_l, const char *,
401 (int category, locale_t locale),
402 _GL_ARG_NONNULL ((2)));
403# endif
404_GL_CXXALIAS_SYS (getlocalename_l, const char *,
405 (int category, locale_t locale));
406# endif
407# if __GLIBC__ >= 2
408_GL_CXXALIASWARN (getlocalename_l);
409# endif
410#elif defined GNULIB_POSIXCHECK
411# undef getlocalename_l
412# if HAVE_RAW_DECL_GETLOCALENAME_L
413_GL_WARN_ON_USE (getlocalename_l, "getlocalename_l is not portable");
414# endif
415#endif
416
308#endif /* _@GUARD_PREFIX@_LOCALE_H */ 417#endif /* _@GUARD_PREFIX@_LOCALE_H */
309#endif /* _@GUARD_PREFIX@_LOCALE_H */ 418#endif /* _@GUARD_PREFIX@_LOCALE_H */
310#endif /* !(__need_locale_t || _GL_ALREADY_INCLUDING_LOCALE_H) */ 419#endif /* !(__need_locale_t || _@GUARD_PREFIX@_ALREADY_INCLUDING_LOCALE_H) */