summaryrefslogtreecommitdiffstats
path: root/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gl')
-rw-r--r--gl/inttypes.h1314
-rw-r--r--gl/limits.h132
-rw-r--r--gl/malloc/dynarray-skeleton.gl.h529
-rw-r--r--gl/malloc/dynarray.gl.h174
4 files changed, 2149 insertions, 0 deletions
diff --git a/gl/inttypes.h b/gl/inttypes.h
new file mode 100644
index 0000000..f721f0e
--- /dev/null
+++ b/gl/inttypes.h
@@ -0,0 +1,1314 @@
1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2/* Copyright (C) 2006-2021 Free Software Foundation, Inc.
3 Written by Paul Eggert, Bruno Haible, Derek Price.
4 This file is part of gnulib.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19/*
20 * ISO C 99 <inttypes.h> for platforms that lack it.
21 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html>
22 */
23
24#if __GNUC__ >= 3
25#pragma GCC system_header
26#endif
27
28
29/* Include the original <inttypes.h> if it exists, and if this file
30 has not been included yet or if this file includes gnulib stdint.h
31 which in turn includes this file.
32 The include_next requires a split double-inclusion guard. */
33#if ! defined INTTYPES_H || defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
34# if 1
35
36 /* Some pre-C++11 <stdint.h> implementations need this. */
37# if defined __cplusplus && ! defined __STDC_FORMAT_MACROS
38# define __STDC_FORMAT_MACROS 1
39# endif
40
41# include_next <inttypes.h>
42
43# define _GL_FINISHED_INCLUDING_SYSTEM_INTTYPES_H
44# endif
45#endif
46
47#if ! defined INTTYPES_H && ! defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
48#define INTTYPES_H
49
50/* Include <stdint.h> or the gnulib replacement.
51 But avoid namespace pollution on glibc systems. */
52#ifndef __GLIBC__
53# include <stdint.h>
54#endif
55/* Get CHAR_BIT, INT_MAX, LONG_MAX, etc. */
56#include <limits.h>
57/* On mingw, __USE_MINGW_ANSI_STDIO only works if <stdio.h> is also included */
58#if defined _WIN32 && ! defined __CYGWIN__
59# include <stdio.h>
60#endif
61
62#if !(INT_MAX == 0x7fffffff && INT_MIN + INT_MAX == -1)
63# error "This file assumes that 'int' is 32-bit two's complement. Please report your platform and compiler to <bug-gnulib@gnu.org>."
64#endif
65
66/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
67#ifndef _GL_CXXDEFS_H
68#define _GL_CXXDEFS_H
69
70/* The three most frequent use cases of these macros are:
71
72 * For providing a substitute for a function that is missing on some
73 platforms, but is declared and works fine on the platforms on which
74 it exists:
75
76 #if @GNULIB_FOO@
77 # if !@HAVE_FOO@
78 _GL_FUNCDECL_SYS (foo, ...);
79 # endif
80 _GL_CXXALIAS_SYS (foo, ...);
81 _GL_CXXALIASWARN (foo);
82 #elif defined GNULIB_POSIXCHECK
83 ...
84 #endif
85
86 * For providing a replacement for a function that exists on all platforms,
87 but is broken/insufficient and needs to be replaced on some platforms:
88
89 #if @GNULIB_FOO@
90 # if @REPLACE_FOO@
91 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
92 # undef foo
93 # define foo rpl_foo
94 # endif
95 _GL_FUNCDECL_RPL (foo, ...);
96 _GL_CXXALIAS_RPL (foo, ...);
97 # else
98 _GL_CXXALIAS_SYS (foo, ...);
99 # endif
100 _GL_CXXALIASWARN (foo);
101 #elif defined GNULIB_POSIXCHECK
102 ...
103 #endif
104
105 * For providing a replacement for a function that exists on some platforms
106 but is broken/insufficient and needs to be replaced on some of them and
107 is additionally either missing or undeclared on some other platforms:
108
109 #if @GNULIB_FOO@
110 # if @REPLACE_FOO@
111 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
112 # undef foo
113 # define foo rpl_foo
114 # endif
115 _GL_FUNCDECL_RPL (foo, ...);
116 _GL_CXXALIAS_RPL (foo, ...);
117 # else
118 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
119 _GL_FUNCDECL_SYS (foo, ...);
120 # endif
121 _GL_CXXALIAS_SYS (foo, ...);
122 # endif
123 _GL_CXXALIASWARN (foo);
124 #elif defined GNULIB_POSIXCHECK
125 ...
126 #endif
127*/
128
129/* _GL_EXTERN_C declaration;
130 performs the declaration with C linkage. */
131#if defined __cplusplus
132# define _GL_EXTERN_C extern "C"
133#else
134# define _GL_EXTERN_C extern
135#endif
136
137/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
138 declares a replacement function, named rpl_func, with the given prototype,
139 consisting of return type, parameters, and attributes.
140 Example:
141 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
142 _GL_ARG_NONNULL ((1)));
143 */
144#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
145 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
146#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
147 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
148
149/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
150 declares the system function, named func, with the given prototype,
151 consisting of return type, parameters, and attributes.
152 Example:
153 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
154 _GL_ARG_NONNULL ((1)));
155 */
156#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
157 _GL_EXTERN_C rettype func parameters_and_attributes
158
159/* _GL_CXXALIAS_RPL (func, rettype, parameters);
160 declares a C++ alias called GNULIB_NAMESPACE::func
161 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
162 Example:
163 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
164 */
165#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
166 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
167#if defined __cplusplus && defined GNULIB_NAMESPACE
168# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
169 namespace GNULIB_NAMESPACE \
170 { \
171 rettype (*const func) parameters = ::rpl_func; \
172 } \
173 _GL_EXTERN_C int _gl_cxxalias_dummy
174#else
175# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
176 _GL_EXTERN_C int _gl_cxxalias_dummy
177#endif
178
179/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
180 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
181 except that the C function rpl_func may have a slightly different
182 declaration. A cast is used to silence the "invalid conversion" error
183 that would otherwise occur. */
184#if defined __cplusplus && defined GNULIB_NAMESPACE
185# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
186 namespace GNULIB_NAMESPACE \
187 { \
188 rettype (*const func) parameters = \
189 reinterpret_cast<rettype(*)parameters>(::rpl_func); \
190 } \
191 _GL_EXTERN_C int _gl_cxxalias_dummy
192#else
193# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
194 _GL_EXTERN_C int _gl_cxxalias_dummy
195#endif
196
197/* _GL_CXXALIAS_SYS (func, rettype, parameters);
198 declares a C++ alias called GNULIB_NAMESPACE::func
199 that redirects to the system provided function func, if GNULIB_NAMESPACE
200 is defined.
201 Example:
202 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
203 */
204#if defined __cplusplus && defined GNULIB_NAMESPACE
205 /* If we were to write
206 rettype (*const func) parameters = ::func;
207 like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
208 better (remove an indirection through a 'static' pointer variable),
209 but then the _GL_CXXALIASWARN macro below would cause a warning not only
210 for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
211# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
212 namespace GNULIB_NAMESPACE \
213 { \
214 static rettype (*func) parameters = ::func; \
215 } \
216 _GL_EXTERN_C int _gl_cxxalias_dummy
217#else
218# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
219 _GL_EXTERN_C int _gl_cxxalias_dummy
220#endif
221
222/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
223 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
224 except that the C function func may have a slightly different declaration.
225 A cast is used to silence the "invalid conversion" error that would
226 otherwise occur. */
227#if defined __cplusplus && defined GNULIB_NAMESPACE
228# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
229 namespace GNULIB_NAMESPACE \
230 { \
231 static rettype (*func) parameters = \
232 reinterpret_cast<rettype(*)parameters>(::func); \
233 } \
234 _GL_EXTERN_C int _gl_cxxalias_dummy
235#else
236# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
237 _GL_EXTERN_C int _gl_cxxalias_dummy
238#endif
239
240/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
241 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
242 except that the C function is picked among a set of overloaded functions,
243 namely the one with rettype2 and parameters2. Two consecutive casts
244 are used to silence the "cannot find a match" and "invalid conversion"
245 errors that would otherwise occur. */
246#if defined __cplusplus && defined GNULIB_NAMESPACE
247 /* The outer cast must be a reinterpret_cast.
248 The inner cast: When the function is defined as a set of overloaded
249 functions, it works as a static_cast<>, choosing the designated variant.
250 When the function is defined as a single variant, it works as a
251 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
252# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
253 namespace GNULIB_NAMESPACE \
254 { \
255 static rettype (*func) parameters = \
256 reinterpret_cast<rettype(*)parameters>( \
257 (rettype2(*)parameters2)(::func)); \
258 } \
259 _GL_EXTERN_C int _gl_cxxalias_dummy
260#else
261# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
262 _GL_EXTERN_C int _gl_cxxalias_dummy
263#endif
264
265/* _GL_CXXALIASWARN (func);
266 causes a warning to be emitted when ::func is used but not when
267 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
268 variants. */
269#if defined __cplusplus && defined GNULIB_NAMESPACE
270# define _GL_CXXALIASWARN(func) \
271 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
272# define _GL_CXXALIASWARN_1(func,namespace) \
273 _GL_CXXALIASWARN_2 (func, namespace)
274/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
275 we enable the warning only when not optimizing. */
276# if !__OPTIMIZE__
277# define _GL_CXXALIASWARN_2(func,namespace) \
278 _GL_WARN_ON_USE (func, \
279 "The symbol ::" #func " refers to the system function. " \
280 "Use " #namespace "::" #func " instead.")
281# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
282# define _GL_CXXALIASWARN_2(func,namespace) \
283 extern __typeof__ (func) func
284# else
285# define _GL_CXXALIASWARN_2(func,namespace) \
286 _GL_EXTERN_C int _gl_cxxalias_dummy
287# endif
288#else
289# define _GL_CXXALIASWARN(func) \
290 _GL_EXTERN_C int _gl_cxxalias_dummy
291#endif
292
293/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
294 causes a warning to be emitted when the given overloaded variant of ::func
295 is used but not when GNULIB_NAMESPACE::func is used. */
296#if defined __cplusplus && defined GNULIB_NAMESPACE
297# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
298 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
299 GNULIB_NAMESPACE)
300# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
301 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
302/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
303 we enable the warning only when not optimizing. */
304# if !__OPTIMIZE__
305# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
306 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
307 "The symbol ::" #func " refers to the system function. " \
308 "Use " #namespace "::" #func " instead.")
309# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
310# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
311 extern __typeof__ (func) func
312# else
313# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
314 _GL_EXTERN_C int _gl_cxxalias_dummy
315# endif
316#else
317# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
318 _GL_EXTERN_C int _gl_cxxalias_dummy
319#endif
320
321#endif /* _GL_CXXDEFS_H */
322
323/* The definition of _GL_ARG_NONNULL is copied here. */
324/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
325 that the values passed as arguments n, ..., m must be non-NULL pointers.
326 n = 1 stands for the first argument, n = 2 for the second argument etc. */
327#ifndef _GL_ARG_NONNULL
328# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
329# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
330# else
331# define _GL_ARG_NONNULL(params)
332# endif
333#endif
334
335/* The definition of _GL_WARN_ON_USE is copied here. */
336#ifndef _GL_WARN_ON_USE
337
338# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
339/* A compiler attribute is available in gcc versions 4.3.0 and later. */
340# define _GL_WARN_ON_USE(function, message) \
341extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
342# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
343/* Verify the existence of the function. */
344# define _GL_WARN_ON_USE(function, message) \
345extern __typeof__ (function) function
346# else /* Unsupported. */
347# define _GL_WARN_ON_USE(function, message) \
348_GL_WARN_EXTERN_C int _gl_warn_on_use
349# endif
350#endif
351
352/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
353 is like _GL_WARN_ON_USE (function, "string"), except that the function is
354 declared with the given prototype, consisting of return type, parameters,
355 and attributes.
356 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
357 not work in this case. */
358#ifndef _GL_WARN_ON_USE_CXX
359# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
360# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
361extern rettype function parameters_and_attributes \
362 __attribute__ ((__warning__ (msg)))
363# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
364/* Verify the existence of the function. */
365# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
366extern rettype function parameters_and_attributes
367# else /* Unsupported. */
368# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
369_GL_WARN_EXTERN_C int _gl_warn_on_use
370# endif
371#endif
372
373/* _GL_WARN_EXTERN_C declaration;
374 performs the declaration with C linkage. */
375#ifndef _GL_WARN_EXTERN_C
376# if defined __cplusplus
377# define _GL_WARN_EXTERN_C extern "C"
378# else
379# define _GL_WARN_EXTERN_C extern
380# endif
381#endif
382
383/* 7.8.1 Macros for format specifiers */
384
385#if defined _TNS_R_TARGET
386 /* Tandem NonStop R series and compatible platforms released before
387 July 2005 support %Ld but not %lld. */
388# define _LONG_LONG_FORMAT_PREFIX "L"
389#else
390# define _LONG_LONG_FORMAT_PREFIX "ll"
391#endif
392
393#if !defined PRId8
394# ifdef INT8_MAX
395# define PRId8 "d"
396# endif
397#endif
398#if !defined PRIi8
399# ifdef INT8_MAX
400# define PRIi8 "i"
401# endif
402#endif
403#if !defined PRIo8
404# ifdef UINT8_MAX
405# define PRIo8 "o"
406# endif
407#endif
408#if !defined PRIu8
409# ifdef UINT8_MAX
410# define PRIu8 "u"
411# endif
412#endif
413#if !defined PRIx8
414# ifdef UINT8_MAX
415# define PRIx8 "x"
416# endif
417#endif
418#if !defined PRIX8
419# ifdef UINT8_MAX
420# define PRIX8 "X"
421# endif
422#endif
423#if !defined PRId16
424# ifdef INT16_MAX
425# define PRId16 "d"
426# endif
427#endif
428#if !defined PRIi16
429# ifdef INT16_MAX
430# define PRIi16 "i"
431# endif
432#endif
433#if !defined PRIo16
434# ifdef UINT16_MAX
435# define PRIo16 "o"
436# endif
437#endif
438#if !defined PRIu16
439# ifdef UINT16_MAX
440# define PRIu16 "u"
441# endif
442#endif
443#if !defined PRIx16
444# ifdef UINT16_MAX
445# define PRIx16 "x"
446# endif
447#endif
448#if !defined PRIX16
449# ifdef UINT16_MAX
450# define PRIX16 "X"
451# endif
452#endif
453#if !defined PRId32
454# ifdef INT32_MAX
455# define PRId32 "d"
456# endif
457#endif
458#if !defined PRIi32
459# ifdef INT32_MAX
460# define PRIi32 "i"
461# endif
462#endif
463#if !defined PRIo32
464# ifdef UINT32_MAX
465# define PRIo32 "o"
466# endif
467#endif
468#if !defined PRIu32
469# ifdef UINT32_MAX
470# define PRIu32 "u"
471# endif
472#endif
473#if !defined PRIx32
474# ifdef UINT32_MAX
475# define PRIx32 "x"
476# endif
477#endif
478#if !defined PRIX32
479# ifdef UINT32_MAX
480# define PRIX32 "X"
481# endif
482#endif
483#ifdef INT64_MAX
484# if (0 ? defined _LP64 : defined _LP64)
485# define _PRI64_PREFIX "l"
486# elif defined _MSC_VER || defined __MINGW32__
487# define _PRI64_PREFIX "I64"
488# elif LONG_MAX >> 30 == 1
489# define _PRI64_PREFIX _LONG_LONG_FORMAT_PREFIX
490# endif
491# if !defined PRId64
492# define PRId64 _PRI64_PREFIX "d"
493# endif
494# if !defined PRIi64
495# define PRIi64 _PRI64_PREFIX "i"
496# endif
497#endif
498#ifdef UINT64_MAX
499# if (0 ? defined _LP64 : defined _LP64)
500# define _PRIu64_PREFIX "l"
501# elif defined _MSC_VER || defined __MINGW32__
502# define _PRIu64_PREFIX "I64"
503# elif ULONG_MAX >> 31 == 1
504# define _PRIu64_PREFIX _LONG_LONG_FORMAT_PREFIX
505# endif
506# if !defined PRIo64
507# define PRIo64 _PRIu64_PREFIX "o"
508# endif
509# if !defined PRIu64
510# define PRIu64 _PRIu64_PREFIX "u"
511# endif
512# if !defined PRIx64
513# define PRIx64 _PRIu64_PREFIX "x"
514# endif
515# if !defined PRIX64
516# define PRIX64 _PRIu64_PREFIX "X"
517# endif
518#endif
519
520#if !defined PRIdLEAST8
521# define PRIdLEAST8 "d"
522#endif
523#if !defined PRIiLEAST8
524# define PRIiLEAST8 "i"
525#endif
526#if !defined PRIoLEAST8
527# define PRIoLEAST8 "o"
528#endif
529#if !defined PRIuLEAST8
530# define PRIuLEAST8 "u"
531#endif
532#if !defined PRIxLEAST8
533# define PRIxLEAST8 "x"
534#endif
535#if !defined PRIXLEAST8
536# define PRIXLEAST8 "X"
537#endif
538#if !defined PRIdLEAST16
539# define PRIdLEAST16 "d"
540#endif
541#if !defined PRIiLEAST16
542# define PRIiLEAST16 "i"
543#endif
544#if !defined PRIoLEAST16
545# define PRIoLEAST16 "o"
546#endif
547#if !defined PRIuLEAST16
548# define PRIuLEAST16 "u"
549#endif
550#if !defined PRIxLEAST16
551# define PRIxLEAST16 "x"
552#endif
553#if !defined PRIXLEAST16
554# define PRIXLEAST16 "X"
555#endif
556#if !defined PRIdLEAST32
557# define PRIdLEAST32 "d"
558#endif
559#if !defined PRIiLEAST32
560# define PRIiLEAST32 "i"
561#endif
562#if !defined PRIoLEAST32
563# define PRIoLEAST32 "o"
564#endif
565#if !defined PRIuLEAST32
566# define PRIuLEAST32 "u"
567#endif
568#if !defined PRIxLEAST32
569# define PRIxLEAST32 "x"
570#endif
571#if !defined PRIXLEAST32
572# define PRIXLEAST32 "X"
573#endif
574#ifdef INT64_MAX
575# if !defined PRIdLEAST64
576# define PRIdLEAST64 PRId64
577# endif
578# if !defined PRIiLEAST64
579# define PRIiLEAST64 PRIi64
580# endif
581#endif
582#ifdef UINT64_MAX
583# if !defined PRIoLEAST64
584# define PRIoLEAST64 PRIo64
585# endif
586# if !defined PRIuLEAST64
587# define PRIuLEAST64 PRIu64
588# endif
589# if !defined PRIxLEAST64
590# define PRIxLEAST64 PRIx64
591# endif
592# if !defined PRIXLEAST64
593# define PRIXLEAST64 PRIX64
594# endif
595#endif
596
597#if !defined PRIdFAST8
598# if INT_FAST8_MAX > INT32_MAX
599# define PRIdFAST8 PRId64
600# else
601# define PRIdFAST8 "d"
602# endif
603#endif
604#if !defined PRIiFAST8
605# if INT_FAST8_MAX > INT32_MAX
606# define PRIiFAST8 PRIi64
607# else
608# define PRIiFAST8 "i"
609# endif
610#endif
611#if !defined PRIoFAST8
612# if UINT_FAST8_MAX > UINT32_MAX
613# define PRIoFAST8 PRIo64
614# else
615# define PRIoFAST8 "o"
616# endif
617#endif
618#if !defined PRIuFAST8
619# if UINT_FAST8_MAX > UINT32_MAX
620# define PRIuFAST8 PRIu64
621# else
622# define PRIuFAST8 "u"
623# endif
624#endif
625#if !defined PRIxFAST8
626# if UINT_FAST8_MAX > UINT32_MAX
627# define PRIxFAST8 PRIx64
628# else
629# define PRIxFAST8 "x"
630# endif
631#endif
632#if !defined PRIXFAST8
633# if UINT_FAST8_MAX > UINT32_MAX
634# define PRIXFAST8 PRIX64
635# else
636# define PRIXFAST8 "X"
637# endif
638#endif
639#if !defined PRIdFAST16
640# if INT_FAST16_MAX > INT32_MAX
641# define PRIdFAST16 PRId64
642# else
643# define PRIdFAST16 "d"
644# endif
645#endif
646#if !defined PRIiFAST16
647# if INT_FAST16_MAX > INT32_MAX
648# define PRIiFAST16 PRIi64
649# else
650# define PRIiFAST16 "i"
651# endif
652#endif
653#if !defined PRIoFAST16
654# if UINT_FAST16_MAX > UINT32_MAX
655# define PRIoFAST16 PRIo64
656# else
657# define PRIoFAST16 "o"
658# endif
659#endif
660#if !defined PRIuFAST16
661# if UINT_FAST16_MAX > UINT32_MAX
662# define PRIuFAST16 PRIu64
663# else
664# define PRIuFAST16 "u"
665# endif
666#endif
667#if !defined PRIxFAST16
668# if UINT_FAST16_MAX > UINT32_MAX
669# define PRIxFAST16 PRIx64
670# else
671# define PRIxFAST16 "x"
672# endif
673#endif
674#if !defined PRIXFAST16
675# if UINT_FAST16_MAX > UINT32_MAX
676# define PRIXFAST16 PRIX64
677# else
678# define PRIXFAST16 "X"
679# endif
680#endif
681#if !defined PRIdFAST32
682# if INT_FAST32_MAX > INT32_MAX
683# define PRIdFAST32 PRId64
684# else
685# define PRIdFAST32 "d"
686# endif
687#endif
688#if !defined PRIiFAST32
689# if INT_FAST32_MAX > INT32_MAX
690# define PRIiFAST32 PRIi64
691# else
692# define PRIiFAST32 "i"
693# endif
694#endif
695#if !defined PRIoFAST32
696# if UINT_FAST32_MAX > UINT32_MAX
697# define PRIoFAST32 PRIo64
698# else
699# define PRIoFAST32 "o"
700# endif
701#endif
702#if !defined PRIuFAST32
703# if UINT_FAST32_MAX > UINT32_MAX
704# define PRIuFAST32 PRIu64
705# else
706# define PRIuFAST32 "u"
707# endif
708#endif
709#if !defined PRIxFAST32
710# if UINT_FAST32_MAX > UINT32_MAX
711# define PRIxFAST32 PRIx64
712# else
713# define PRIxFAST32 "x"
714# endif
715#endif
716#if !defined PRIXFAST32
717# if UINT_FAST32_MAX > UINT32_MAX
718# define PRIXFAST32 PRIX64
719# else
720# define PRIXFAST32 "X"
721# endif
722#endif
723#ifdef INT64_MAX
724# if !defined PRIdFAST64
725# define PRIdFAST64 PRId64
726# endif
727# if !defined PRIiFAST64
728# define PRIiFAST64 PRIi64
729# endif
730#endif
731#ifdef UINT64_MAX
732# if !defined PRIoFAST64
733# define PRIoFAST64 PRIo64
734# endif
735# if !defined PRIuFAST64
736# define PRIuFAST64 PRIu64
737# endif
738# if !defined PRIxFAST64
739# define PRIxFAST64 PRIx64
740# endif
741# if !defined PRIXFAST64
742# define PRIXFAST64 PRIX64
743# endif
744#endif
745
746#if !defined PRIdMAX
747# if 1
748# define PRIdMAX PRId64
749# else
750# define PRIdMAX "ld"
751# endif
752#endif
753#if !defined PRIiMAX
754# if 1
755# define PRIiMAX PRIi64
756# else
757# define PRIiMAX "li"
758# endif
759#endif
760#if !defined PRIoMAX
761# if 1
762# define PRIoMAX PRIo64
763# else
764# define PRIoMAX "lo"
765# endif
766#endif
767#if !defined PRIuMAX
768# if 1
769# define PRIuMAX PRIu64
770# else
771# define PRIuMAX "lu"
772# endif
773#endif
774#if !defined PRIxMAX
775# if 1
776# define PRIxMAX PRIx64
777# else
778# define PRIxMAX "lx"
779# endif
780#endif
781#if !defined PRIXMAX
782# if 1
783# define PRIXMAX PRIX64
784# else
785# define PRIXMAX "lX"
786# endif
787#endif
788
789#if !defined PRIdPTR
790# ifdef INTPTR_MAX
791# define PRIdPTR __PRIPTR_PREFIX "d"
792# endif
793#endif
794#if !defined PRIiPTR
795# ifdef INTPTR_MAX
796# define PRIiPTR __PRIPTR_PREFIX "i"
797# endif
798#endif
799#if !defined PRIoPTR
800# ifdef UINTPTR_MAX
801# define PRIoPTR __PRIPTR_PREFIX "o"
802# endif
803#endif
804#if !defined PRIuPTR
805# ifdef UINTPTR_MAX
806# define PRIuPTR __PRIPTR_PREFIX "u"
807# endif
808#endif
809#if !defined PRIxPTR
810# ifdef UINTPTR_MAX
811# define PRIxPTR __PRIPTR_PREFIX "x"
812# endif
813#endif
814#if !defined PRIXPTR
815# ifdef UINTPTR_MAX
816# define PRIXPTR __PRIPTR_PREFIX "X"
817# endif
818#endif
819
820#if !defined SCNd8
821# ifdef INT8_MAX
822# define SCNd8 "hhd"
823# endif
824#endif
825#if !defined SCNi8
826# ifdef INT8_MAX
827# define SCNi8 "hhi"
828# endif
829#endif
830#if !defined SCNo8
831# ifdef UINT8_MAX
832# define SCNo8 "hho"
833# endif
834#endif
835#if !defined SCNu8
836# ifdef UINT8_MAX
837# define SCNu8 "hhu"
838# endif
839#endif
840#if !defined SCNx8
841# ifdef UINT8_MAX
842# define SCNx8 "hhx"
843# endif
844#endif
845#if !defined SCNd16
846# ifdef INT16_MAX
847# define SCNd16 "hd"
848# endif
849#endif
850#if !defined SCNi16
851# ifdef INT16_MAX
852# define SCNi16 "hi"
853# endif
854#endif
855#if !defined SCNo16
856# ifdef UINT16_MAX
857# define SCNo16 "ho"
858# endif
859#endif
860#if !defined SCNu16
861# ifdef UINT16_MAX
862# define SCNu16 "hu"
863# endif
864#endif
865#if !defined SCNx16
866# ifdef UINT16_MAX
867# define SCNx16 "hx"
868# endif
869#endif
870#if !defined SCNd32
871# ifdef INT32_MAX
872# define SCNd32 "d"
873# endif
874#endif
875#if !defined SCNi32
876# ifdef INT32_MAX
877# define SCNi32 "i"
878# endif
879#endif
880#if !defined SCNo32
881# ifdef UINT32_MAX
882# define SCNo32 "o"
883# endif
884#endif
885#if !defined SCNu32
886# ifdef UINT32_MAX
887# define SCNu32 "u"
888# endif
889#endif
890#if !defined SCNx32
891# ifdef UINT32_MAX
892# define SCNx32 "x"
893# endif
894#endif
895#ifdef INT64_MAX
896# if (0 ? defined _LP64 : defined _LP64)
897# define _SCN64_PREFIX "l"
898# elif defined _MSC_VER || defined __MINGW32__
899# define _SCN64_PREFIX "I64"
900# elif LONG_MAX >> 30 == 1
901# define _SCN64_PREFIX _LONG_LONG_FORMAT_PREFIX
902# endif
903# if !defined SCNd64
904# define SCNd64 _SCN64_PREFIX "d"
905# endif
906# if !defined SCNi64
907# define SCNi64 _SCN64_PREFIX "i"
908# endif
909#endif
910#ifdef UINT64_MAX
911# if (0 ? defined _LP64 : defined _LP64)
912# define _SCNu64_PREFIX "l"
913# elif defined _MSC_VER || defined __MINGW32__
914# define _SCNu64_PREFIX "I64"
915# elif ULONG_MAX >> 31 == 1
916# define _SCNu64_PREFIX _LONG_LONG_FORMAT_PREFIX
917# endif
918# if !defined SCNo64
919# define SCNo64 _SCNu64_PREFIX "o"
920# endif
921# if !defined SCNu64
922# define SCNu64 _SCNu64_PREFIX "u"
923# endif
924# if !defined SCNx64
925# define SCNx64 _SCNu64_PREFIX "x"
926# endif
927#endif
928
929#if !defined SCNdLEAST8
930# define SCNdLEAST8 "hhd"
931#endif
932#if !defined SCNiLEAST8
933# define SCNiLEAST8 "hhi"
934#endif
935#if !defined SCNoLEAST8
936# define SCNoLEAST8 "hho"
937#endif
938#if !defined SCNuLEAST8
939# define SCNuLEAST8 "hhu"
940#endif
941#if !defined SCNxLEAST8
942# define SCNxLEAST8 "hhx"
943#endif
944#if !defined SCNdLEAST16
945# define SCNdLEAST16 "hd"
946#endif
947#if !defined SCNiLEAST16
948# define SCNiLEAST16 "hi"
949#endif
950#if !defined SCNoLEAST16
951# define SCNoLEAST16 "ho"
952#endif
953#if !defined SCNuLEAST16
954# define SCNuLEAST16 "hu"
955#endif
956#if !defined SCNxLEAST16
957# define SCNxLEAST16 "hx"
958#endif
959#if !defined SCNdLEAST32
960# define SCNdLEAST32 "d"
961#endif
962#if !defined SCNiLEAST32
963# define SCNiLEAST32 "i"
964#endif
965#if !defined SCNoLEAST32
966# define SCNoLEAST32 "o"
967#endif
968#if !defined SCNuLEAST32
969# define SCNuLEAST32 "u"
970#endif
971#if !defined SCNxLEAST32
972# define SCNxLEAST32 "x"
973#endif
974#ifdef INT64_MAX
975# if !defined SCNdLEAST64
976# define SCNdLEAST64 SCNd64
977# endif
978# if !defined SCNiLEAST64
979# define SCNiLEAST64 SCNi64
980# endif
981#endif
982#ifdef UINT64_MAX
983# if !defined SCNoLEAST64
984# define SCNoLEAST64 SCNo64
985# endif
986# if !defined SCNuLEAST64
987# define SCNuLEAST64 SCNu64
988# endif
989# if !defined SCNxLEAST64
990# define SCNxLEAST64 SCNx64
991# endif
992#endif
993
994#if !defined SCNdFAST8
995# if INT_FAST8_MAX > INT32_MAX
996# define SCNdFAST8 SCNd64
997# elif INT_FAST8_MAX == 0x7fff
998# define SCNdFAST8 "hd"
999# elif INT_FAST8_MAX == 0x7f
1000# define SCNdFAST8 "hhd"
1001# else
1002# define SCNdFAST8 "d"
1003# endif
1004#endif
1005#if !defined SCNiFAST8
1006# if INT_FAST8_MAX > INT32_MAX
1007# define SCNiFAST8 SCNi64
1008# elif INT_FAST8_MAX == 0x7fff
1009# define SCNiFAST8 "hi"
1010# elif INT_FAST8_MAX == 0x7f
1011# define SCNiFAST8 "hhi"
1012# else
1013# define SCNiFAST8 "i"
1014# endif
1015#endif
1016#if !defined SCNoFAST8
1017# if UINT_FAST8_MAX > UINT32_MAX
1018# define SCNoFAST8 SCNo64
1019# elif UINT_FAST8_MAX == 0xffff
1020# define SCNoFAST8 "ho"
1021# elif UINT_FAST8_MAX == 0xff
1022# define SCNoFAST8 "hho"
1023# else
1024# define SCNoFAST8 "o"
1025# endif
1026#endif
1027#if !defined SCNuFAST8
1028# if UINT_FAST8_MAX > UINT32_MAX
1029# define SCNuFAST8 SCNu64
1030# elif UINT_FAST8_MAX == 0xffff
1031# define SCNuFAST8 "hu"
1032# elif UINT_FAST8_MAX == 0xff
1033# define SCNuFAST8 "hhu"
1034# else
1035# define SCNuFAST8 "u"
1036# endif
1037#endif
1038#if !defined SCNxFAST8
1039# if UINT_FAST8_MAX > UINT32_MAX
1040# define SCNxFAST8 SCNx64
1041# elif UINT_FAST8_MAX == 0xffff
1042# define SCNxFAST8 "hx"
1043# elif UINT_FAST8_MAX == 0xff
1044# define SCNxFAST8 "hhx"
1045# else
1046# define SCNxFAST8 "x"
1047# endif
1048#endif
1049#if !defined SCNdFAST16
1050# if INT_FAST16_MAX > INT32_MAX
1051# define SCNdFAST16 SCNd64
1052# elif INT_FAST16_MAX == 0x7fff
1053# define SCNdFAST16 "hd"
1054# else
1055# define SCNdFAST16 "d"
1056# endif
1057#endif
1058#if !defined SCNiFAST16
1059# if INT_FAST16_MAX > INT32_MAX
1060# define SCNiFAST16 SCNi64
1061# elif INT_FAST16_MAX == 0x7fff
1062# define SCNiFAST16 "hi"
1063# else
1064# define SCNiFAST16 "i"
1065# endif
1066#endif
1067#if !defined SCNoFAST16
1068# if UINT_FAST16_MAX > UINT32_MAX
1069# define SCNoFAST16 SCNo64
1070# elif UINT_FAST16_MAX == 0xffff
1071# define SCNoFAST16 "ho"
1072# else
1073# define SCNoFAST16 "o"
1074# endif
1075#endif
1076#if !defined SCNuFAST16
1077# if UINT_FAST16_MAX > UINT32_MAX
1078# define SCNuFAST16 SCNu64
1079# elif UINT_FAST16_MAX == 0xffff
1080# define SCNuFAST16 "hu"
1081# else
1082# define SCNuFAST16 "u"
1083# endif
1084#endif
1085#if !defined SCNxFAST16
1086# if UINT_FAST16_MAX > UINT32_MAX
1087# define SCNxFAST16 SCNx64
1088# elif UINT_FAST16_MAX == 0xffff
1089# define SCNxFAST16 "hx"
1090# else
1091# define SCNxFAST16 "x"
1092# endif
1093#endif
1094#if !defined SCNdFAST32
1095# if INT_FAST32_MAX > INT32_MAX
1096# define SCNdFAST32 SCNd64
1097# else
1098# define SCNdFAST32 "d"
1099# endif
1100#endif
1101#if !defined SCNiFAST32
1102# if INT_FAST32_MAX > INT32_MAX
1103# define SCNiFAST32 SCNi64
1104# else
1105# define SCNiFAST32 "i"
1106# endif
1107#endif
1108#if !defined SCNoFAST32
1109# if UINT_FAST32_MAX > UINT32_MAX
1110# define SCNoFAST32 SCNo64
1111# else
1112# define SCNoFAST32 "o"
1113# endif
1114#endif
1115#if !defined SCNuFAST32
1116# if UINT_FAST32_MAX > UINT32_MAX
1117# define SCNuFAST32 SCNu64
1118# else
1119# define SCNuFAST32 "u"
1120# endif
1121#endif
1122#if !defined SCNxFAST32
1123# if UINT_FAST32_MAX > UINT32_MAX
1124# define SCNxFAST32 SCNx64
1125# else
1126# define SCNxFAST32 "x"
1127# endif
1128#endif
1129#ifdef INT64_MAX
1130# if !defined SCNdFAST64
1131# define SCNdFAST64 SCNd64
1132# endif
1133# if !defined SCNiFAST64
1134# define SCNiFAST64 SCNi64
1135# endif
1136#endif
1137#ifdef UINT64_MAX
1138# if !defined SCNoFAST64
1139# define SCNoFAST64 SCNo64
1140# endif
1141# if !defined SCNuFAST64
1142# define SCNuFAST64 SCNu64
1143# endif
1144# if !defined SCNxFAST64
1145# define SCNxFAST64 SCNx64
1146# endif
1147#endif
1148
1149#if !defined SCNdMAX
1150# if 1
1151# define SCNdMAX SCNd64
1152# else
1153# define SCNdMAX "ld"
1154# endif
1155#endif
1156#if !defined SCNiMAX
1157# if 1
1158# define SCNiMAX SCNi64
1159# else
1160# define SCNiMAX "li"
1161# endif
1162#endif
1163#if !defined SCNoMAX
1164# if 1
1165# define SCNoMAX SCNo64
1166# else
1167# define SCNoMAX "lo"
1168# endif
1169#endif
1170#if !defined SCNuMAX
1171# if 1
1172# define SCNuMAX SCNu64
1173# else
1174# define SCNuMAX "lu"
1175# endif
1176#endif
1177#if !defined SCNxMAX
1178# if 1
1179# define SCNxMAX SCNx64
1180# else
1181# define SCNxMAX "lx"
1182# endif
1183#endif
1184
1185#if !defined SCNdPTR
1186# ifdef INTPTR_MAX
1187# define SCNdPTR __PRIPTR_PREFIX "d"
1188# endif
1189#endif
1190#if !defined SCNiPTR
1191# ifdef INTPTR_MAX
1192# define SCNiPTR __PRIPTR_PREFIX "i"
1193# endif
1194#endif
1195#if !defined SCNoPTR
1196# ifdef UINTPTR_MAX
1197# define SCNoPTR __PRIPTR_PREFIX "o"
1198# endif
1199#endif
1200#if !defined SCNuPTR
1201# ifdef UINTPTR_MAX
1202# define SCNuPTR __PRIPTR_PREFIX "u"
1203# endif
1204#endif
1205#if !defined SCNxPTR
1206# ifdef UINTPTR_MAX
1207# define SCNxPTR __PRIPTR_PREFIX "x"
1208# endif
1209#endif
1210
1211/* 7.8.2 Functions for greatest-width integer types */
1212
1213#ifdef __cplusplus
1214extern "C" {
1215#endif
1216
1217#if 0
1218# if !1
1219extern intmax_t imaxabs (intmax_t);
1220# endif
1221#elif defined GNULIB_POSIXCHECK
1222# undef imaxabs
1223# if HAVE_RAW_DECL_IMAXABS
1224_GL_WARN_ON_USE (imaxabs, "imaxabs is unportable - "
1225 "use gnulib module imaxabs for portability");
1226# endif
1227#endif
1228
1229#if 0
1230# if !1
1231# if !GNULIB_defined_imaxdiv_t
1232typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
1233# define GNULIB_defined_imaxdiv_t 1
1234# endif
1235# endif
1236# if !1
1237extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
1238# endif
1239#elif defined GNULIB_POSIXCHECK
1240# undef imaxdiv
1241# if HAVE_RAW_DECL_IMAXDIV
1242_GL_WARN_ON_USE (imaxdiv, "imaxdiv is unportable - "
1243 "use gnulib module imaxdiv for portability");
1244# endif
1245#endif
1246
1247#if 0
1248# if 0
1249# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1250# undef strtoimax
1251# define strtoimax rpl_strtoimax
1252# endif
1253_GL_FUNCDECL_RPL (strtoimax, intmax_t,
1254 (const char *restrict, char **restrict, int)
1255 _GL_ARG_NONNULL ((1)));
1256_GL_CXXALIAS_RPL (strtoimax, intmax_t,
1257 (const char *restrict, char **restrict, int));
1258# else
1259# if !1
1260# undef strtoimax
1261_GL_FUNCDECL_SYS (strtoimax, intmax_t,
1262 (const char *restrict, char **restrict, int)
1263 _GL_ARG_NONNULL ((1)));
1264# endif
1265_GL_CXXALIAS_SYS (strtoimax, intmax_t,
1266 (const char *restrict, char **restrict, int));
1267# endif
1268_GL_CXXALIASWARN (strtoimax);
1269#elif defined GNULIB_POSIXCHECK
1270# undef strtoimax
1271# if HAVE_RAW_DECL_STRTOIMAX
1272_GL_WARN_ON_USE (strtoimax, "strtoimax is unportable - "
1273 "use gnulib module strtoimax for portability");
1274# endif
1275#endif
1276
1277#if 0
1278# if 0
1279# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1280# undef strtoumax
1281# define strtoumax rpl_strtoumax
1282# endif
1283_GL_FUNCDECL_RPL (strtoumax, uintmax_t,
1284 (const char *restrict, char **restrict, int)
1285 _GL_ARG_NONNULL ((1)));
1286_GL_CXXALIAS_RPL (strtoumax, uintmax_t,
1287 (const char *restrict, char **restrict, int));
1288# else
1289# if !1
1290# undef strtoumax
1291_GL_FUNCDECL_SYS (strtoumax, uintmax_t,
1292 (const char *restrict, char **restrict, int)
1293 _GL_ARG_NONNULL ((1)));
1294# endif
1295_GL_CXXALIAS_SYS (strtoumax, uintmax_t,
1296 (const char *restrict, char **restrict, int));
1297# endif
1298_GL_CXXALIASWARN (strtoumax);
1299#elif defined GNULIB_POSIXCHECK
1300# undef strtoumax
1301# if HAVE_RAW_DECL_STRTOUMAX
1302_GL_WARN_ON_USE (strtoumax, "strtoumax is unportable - "
1303 "use gnulib module strtoumax for portability");
1304# endif
1305#endif
1306
1307/* Don't bother defining or declaring wcstoimax and wcstoumax, since
1308 wide-character functions like this are hardly ever useful. */
1309
1310#ifdef __cplusplus
1311}
1312#endif
1313
1314#endif /* !defined INTTYPES_H && !defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H */
diff --git a/gl/limits.h b/gl/limits.h
new file mode 100644
index 0000000..bf2dca2
--- /dev/null
+++ b/gl/limits.h
@@ -0,0 +1,132 @@
1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2/* A GNU-like <limits.h>.
3
4 Copyright 2016-2021 Free Software Foundation, Inc.
5
6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18
19#if __GNUC__ >= 3
20#pragma GCC system_header
21#endif
22
23
24#if defined _GL_ALREADY_INCLUDING_LIMITS_H
25/* Special invocation convention:
26 On Haiku/x86_64, we have a sequence of nested includes
27 <limits.h> -> <syslimits.h> -> <limits.h>.
28 In this situation, LONG_MAX and INT_MAX are not yet defined,
29 therefore we should not attempt to define LONG_BIT. */
30
31#include_next <limits.h>
32
33#else
34/* Normal invocation convention. */
35
36#ifndef _GL_LIMITS_H
37
38# define _GL_ALREADY_INCLUDING_LIMITS_H
39
40/* The include_next requires a split double-inclusion guard. */
41# include_next <limits.h>
42
43# undef _GL_ALREADY_INCLUDING_LIMITS_H
44
45#ifndef _GL_LIMITS_H
46#define _GL_LIMITS_H
47
48#ifndef LLONG_MIN
49# if defined LONG_LONG_MIN /* HP-UX 11.31 */
50# define LLONG_MIN LONG_LONG_MIN
51# elif defined LONGLONG_MIN /* IRIX 6.5 */
52# define LLONG_MIN LONGLONG_MIN
53# elif defined __GNUC__
54# define LLONG_MIN (- __LONG_LONG_MAX__ - 1LL)
55# endif
56#endif
57#ifndef LLONG_MAX
58# if defined LONG_LONG_MAX /* HP-UX 11.31 */
59# define LLONG_MAX LONG_LONG_MAX
60# elif defined LONGLONG_MAX /* IRIX 6.5 */
61# define LLONG_MAX LONGLONG_MAX
62# elif defined __GNUC__
63# define LLONG_MAX __LONG_LONG_MAX__
64# endif
65#endif
66#ifndef ULLONG_MAX
67# if defined ULONG_LONG_MAX /* HP-UX 11.31 */
68# define ULLONG_MAX ULONG_LONG_MAX
69# elif defined ULONGLONG_MAX /* IRIX 6.5 */
70# define ULLONG_MAX ULONGLONG_MAX
71# elif defined __GNUC__
72# define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1ULL)
73# endif
74#endif
75
76/* The number of usable bits in an unsigned or signed integer type
77 with minimum value MIN and maximum value MAX, as an int expression
78 suitable in #if. Cover all known practical hosts. This
79 implementation exploits the fact that MAX is 1 less than a power of
80 2, and merely counts the number of 1 bits in MAX; "COBn" means
81 "count the number of 1 bits in the low-order n bits"). */
82#define _GL_INTEGER_WIDTH(min, max) (((min) < 0) + _GL_COB128 (max))
83#define _GL_COB128(n) (_GL_COB64 ((n) >> 31 >> 31 >> 2) + _GL_COB64 (n))
84#define _GL_COB64(n) (_GL_COB32 ((n) >> 31 >> 1) + _GL_COB32 (n))
85#define _GL_COB32(n) (_GL_COB16 ((n) >> 16) + _GL_COB16 (n))
86#define _GL_COB16(n) (_GL_COB8 ((n) >> 8) + _GL_COB8 (n))
87#define _GL_COB8(n) (_GL_COB4 ((n) >> 4) + _GL_COB4 (n))
88#define _GL_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + !!((n) & 1))
89
90#ifndef WORD_BIT
91/* Assume 'int' is 32 bits wide. */
92# define WORD_BIT 32
93#endif
94#ifndef LONG_BIT
95/* Assume 'long' is 32 or 64 bits wide. */
96# if LONG_MAX == INT_MAX
97# define LONG_BIT 32
98# else
99# define LONG_BIT 64
100# endif
101#endif
102
103/* Macros specified by C2x and by ISO/IEC TS 18661-1:2014. */
104
105#if (! defined ULLONG_WIDTH \
106 && (defined _GNU_SOURCE || defined __STDC_WANT_IEC_60559_BFP_EXT__ \
107 || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
108# define CHAR_WIDTH _GL_INTEGER_WIDTH (CHAR_MIN, CHAR_MAX)
109# define SCHAR_WIDTH _GL_INTEGER_WIDTH (SCHAR_MIN, SCHAR_MAX)
110# define UCHAR_WIDTH _GL_INTEGER_WIDTH (0, UCHAR_MAX)
111# define SHRT_WIDTH _GL_INTEGER_WIDTH (SHRT_MIN, SHRT_MAX)
112# define USHRT_WIDTH _GL_INTEGER_WIDTH (0, USHRT_MAX)
113# define INT_WIDTH _GL_INTEGER_WIDTH (INT_MIN, INT_MAX)
114# define UINT_WIDTH _GL_INTEGER_WIDTH (0, UINT_MAX)
115# define LONG_WIDTH _GL_INTEGER_WIDTH (LONG_MIN, LONG_MAX)
116# define ULONG_WIDTH _GL_INTEGER_WIDTH (0, ULONG_MAX)
117# define LLONG_WIDTH _GL_INTEGER_WIDTH (LLONG_MIN, LLONG_MAX)
118# define ULLONG_WIDTH _GL_INTEGER_WIDTH (0, ULLONG_MAX)
119#endif
120
121/* Macros specified by C2x. */
122
123#if (! defined BOOL_WIDTH \
124 && (defined _GNU_SOURCE \
125 || (defined __STDC_VERSION__ && 201710 < __STDC_VERSION__)))
126# define BOOL_MAX 1
127# define BOOL_WIDTH 1
128#endif
129
130#endif /* _GL_LIMITS_H */
131#endif /* _GL_LIMITS_H */
132#endif
diff --git a/gl/malloc/dynarray-skeleton.gl.h b/gl/malloc/dynarray-skeleton.gl.h
new file mode 100644
index 0000000..b48c6a9
--- /dev/null
+++ b/gl/malloc/dynarray-skeleton.gl.h
@@ -0,0 +1,529 @@
1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2/* Type-safe arrays which grow dynamically.
3 Copyright (C) 2017-2021 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20/* Pre-processor macros which act as parameters:
21
22 DYNARRAY_STRUCT
23 The struct tag of dynamic array to be defined.
24 DYNARRAY_ELEMENT
25 The type name of the element type. Elements are copied
26 as if by memcpy, and can change address as the dynamic
27 array grows.
28 DYNARRAY_PREFIX
29 The prefix of the functions which are defined.
30
31 The following parameters are optional:
32
33 DYNARRAY_ELEMENT_FREE
34 DYNARRAY_ELEMENT_FREE (E) is evaluated to deallocate the
35 contents of elements. E is of type DYNARRAY_ELEMENT *.
36 DYNARRAY_ELEMENT_INIT
37 DYNARRAY_ELEMENT_INIT (E) is evaluated to initialize a new
38 element. E is of type DYNARRAY_ELEMENT *.
39 If DYNARRAY_ELEMENT_FREE but not DYNARRAY_ELEMENT_INIT is
40 defined, new elements are automatically zero-initialized.
41 Otherwise, new elements have undefined contents.
42 DYNARRAY_INITIAL_SIZE
43 The size of the statically allocated array (default:
44 at least 2, more elements if they fit into 128 bytes).
45 Must be a preprocessor constant. If DYNARRAY_INITIAL_SIZE is 0,
46 there is no statically allocated array at, and all non-empty
47 arrays are heap-allocated.
48 DYNARRAY_FINAL_TYPE
49 The name of the type which holds the final array. If not
50 defined, is PREFIX##finalize not provided. DYNARRAY_FINAL_TYPE
51 must be a struct type, with members of type DYNARRAY_ELEMENT and
52 size_t at the start (in this order).
53
54 These macros are undefined after this header file has been
55 included.
56
57 The following types are provided (their members are private to the
58 dynarray implementation):
59
60 struct DYNARRAY_STRUCT
61
62 The following functions are provided:
63
64 void DYNARRAY_PREFIX##init (struct DYNARRAY_STRUCT *);
65 void DYNARRAY_PREFIX##free (struct DYNARRAY_STRUCT *);
66 bool DYNARRAY_PREFIX##has_failed (const struct DYNARRAY_STRUCT *);
67 void DYNARRAY_PREFIX##mark_failed (struct DYNARRAY_STRUCT *);
68 size_t DYNARRAY_PREFIX##size (const struct DYNARRAY_STRUCT *);
69 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##begin (const struct DYNARRAY_STRUCT *);
70 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##end (const struct DYNARRAY_STRUCT *);
71 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##at (struct DYNARRAY_STRUCT *, size_t);
72 void DYNARRAY_PREFIX##add (struct DYNARRAY_STRUCT *, DYNARRAY_ELEMENT);
73 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##emplace (struct DYNARRAY_STRUCT *);
74 bool DYNARRAY_PREFIX##resize (struct DYNARRAY_STRUCT *, size_t);
75 void DYNARRAY_PREFIX##remove_last (struct DYNARRAY_STRUCT *);
76 void DYNARRAY_PREFIX##clear (struct DYNARRAY_STRUCT *);
77
78 The following functions are provided are provided if the
79 prerequisites are met:
80
81 bool DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *,
82 DYNARRAY_FINAL_TYPE *);
83 (if DYNARRAY_FINAL_TYPE is defined)
84 DYNARRAY_ELEMENT *DYNARRAY_PREFIX##finalize (struct DYNARRAY_STRUCT *,
85 size_t *);
86 (if DYNARRAY_FINAL_TYPE is not defined)
87*/
88
89#include <malloc/dynarray.gl.h>
90
91#include <errno.h>
92#include <stdlib.h>
93#include <string.h>
94
95#ifndef DYNARRAY_STRUCT
96# error "DYNARRAY_STRUCT must be defined"
97#endif
98
99#ifndef DYNARRAY_ELEMENT
100# error "DYNARRAY_ELEMENT must be defined"
101#endif
102
103#ifndef DYNARRAY_PREFIX
104# error "DYNARRAY_PREFIX must be defined"
105#endif
106
107#ifdef DYNARRAY_INITIAL_SIZE
108# if DYNARRAY_INITIAL_SIZE < 0
109# error "DYNARRAY_INITIAL_SIZE must be non-negative"
110# endif
111# if DYNARRAY_INITIAL_SIZE > 0
112# define DYNARRAY_HAVE_SCRATCH 1
113# else
114# define DYNARRAY_HAVE_SCRATCH 0
115# endif
116#else
117/* Provide a reasonable default which limits the size of
118 DYNARRAY_STRUCT. */
119# define DYNARRAY_INITIAL_SIZE \
120 (sizeof (DYNARRAY_ELEMENT) > 64 ? 2 : 128 / sizeof (DYNARRAY_ELEMENT))
121# define DYNARRAY_HAVE_SCRATCH 1
122#endif
123
124/* Public type definitions. */
125
126/* All fields of this struct are private to the implementation. */
127struct DYNARRAY_STRUCT
128{
129 union
130 {
131 struct dynarray_header dynarray_abstract;
132 struct
133 {
134 /* These fields must match struct dynarray_header. */
135 size_t used;
136 size_t allocated;
137 DYNARRAY_ELEMENT *array;
138 } dynarray_header;
139 } u;
140
141#if DYNARRAY_HAVE_SCRATCH
142 /* Initial inline allocation. */
143 DYNARRAY_ELEMENT scratch[DYNARRAY_INITIAL_SIZE];
144#endif
145};
146
147/* Internal use only: Helper macros. */
148
149/* Ensure macro-expansion of DYNARRAY_PREFIX. */
150#define DYNARRAY_CONCAT0(prefix, name) prefix##name
151#define DYNARRAY_CONCAT1(prefix, name) DYNARRAY_CONCAT0(prefix, name)
152#define DYNARRAY_NAME(name) DYNARRAY_CONCAT1(DYNARRAY_PREFIX, name)
153
154/* Use DYNARRAY_FREE instead of DYNARRAY_NAME (free),
155 so that Gnulib does not change 'free' to 'rpl_free'. */
156#define DYNARRAY_FREE DYNARRAY_CONCAT1 (DYNARRAY_NAME (f), ree)
157
158/* Address of the scratch buffer if any. */
159#if DYNARRAY_HAVE_SCRATCH
160# define DYNARRAY_SCRATCH(list) (list)->scratch
161#else
162# define DYNARRAY_SCRATCH(list) NULL
163#endif
164
165/* Internal use only: Helper functions. */
166
167/* Internal function. Call DYNARRAY_ELEMENT_FREE with the array
168 elements. Name mangling needed due to the DYNARRAY_ELEMENT_FREE
169 macro expansion. */
170static inline void
171DYNARRAY_NAME (free__elements__) (DYNARRAY_ELEMENT *__dynarray_array,
172 size_t __dynarray_used)
173{
174#ifdef DYNARRAY_ELEMENT_FREE
175 for (size_t __dynarray_i = 0; __dynarray_i < __dynarray_used; ++__dynarray_i)
176 DYNARRAY_ELEMENT_FREE (&__dynarray_array[__dynarray_i]);
177#endif /* DYNARRAY_ELEMENT_FREE */
178}
179
180/* Internal function. Free the non-scratch array allocation. */
181static inline void
182DYNARRAY_NAME (free__array__) (struct DYNARRAY_STRUCT *list)
183{
184#if DYNARRAY_HAVE_SCRATCH
185 if (list->u.dynarray_header.array != list->scratch)
186 free (list->u.dynarray_header.array);
187#else
188 free (list->u.dynarray_header.array);
189#endif
190}
191
192/* Public functions. */
193
194/* Initialize a dynamic array object. This must be called before any
195 use of the object. */
196_GL_ATTRIBUTE_NONNULL ((1))
197static void
198DYNARRAY_NAME (init) (struct DYNARRAY_STRUCT *list)
199{
200 list->u.dynarray_header.used = 0;
201 list->u.dynarray_header.allocated = DYNARRAY_INITIAL_SIZE;
202 list->u.dynarray_header.array = DYNARRAY_SCRATCH (list);
203}
204
205/* Deallocate the dynamic array and its elements. */
206_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NONNULL ((1))
207static void
208DYNARRAY_FREE (struct DYNARRAY_STRUCT *list)
209{
210 DYNARRAY_NAME (free__elements__)
211 (list->u.dynarray_header.array, list->u.dynarray_header.used);
212 DYNARRAY_NAME (free__array__) (list);
213 DYNARRAY_NAME (init) (list);
214}
215
216/* Return true if the dynamic array is in an error state. */
217_GL_ATTRIBUTE_NONNULL ((1))
218static inline bool
219DYNARRAY_NAME (has_failed) (const struct DYNARRAY_STRUCT *list)
220{
221 return list->u.dynarray_header.allocated == __dynarray_error_marker ();
222}
223
224/* Mark the dynamic array as failed. All elements are deallocated as
225 a side effect. */
226_GL_ATTRIBUTE_NONNULL ((1))
227static void
228DYNARRAY_NAME (mark_failed) (struct DYNARRAY_STRUCT *list)
229{
230 DYNARRAY_NAME (free__elements__)
231 (list->u.dynarray_header.array, list->u.dynarray_header.used);
232 DYNARRAY_NAME (free__array__) (list);
233 list->u.dynarray_header.array = DYNARRAY_SCRATCH (list);
234 list->u.dynarray_header.used = 0;
235 list->u.dynarray_header.allocated = __dynarray_error_marker ();
236}
237
238/* Return the number of elements which have been added to the dynamic
239 array. */
240_GL_ATTRIBUTE_NONNULL ((1))
241static inline size_t
242DYNARRAY_NAME (size) (const struct DYNARRAY_STRUCT *list)
243{
244 return list->u.dynarray_header.used;
245}
246
247/* Return a pointer to the array element at INDEX. Terminate the
248 process if INDEX is out of bounds. */
249_GL_ATTRIBUTE_NONNULL ((1))
250static inline DYNARRAY_ELEMENT *
251DYNARRAY_NAME (at) (struct DYNARRAY_STRUCT *list, size_t index)
252{
253 if (_GL_UNLIKELY (index >= DYNARRAY_NAME (size) (list)))
254 __libc_dynarray_at_failure (DYNARRAY_NAME (size) (list), index);
255 return list->u.dynarray_header.array + index;
256}
257
258/* Return a pointer to the first array element, if any. For a
259 zero-length array, the pointer can be NULL even though the dynamic
260 array has not entered the failure state. */
261_GL_ATTRIBUTE_NONNULL ((1))
262static inline DYNARRAY_ELEMENT *
263DYNARRAY_NAME (begin) (struct DYNARRAY_STRUCT *list)
264{
265 return list->u.dynarray_header.array;
266}
267
268/* Return a pointer one element past the last array element. For a
269 zero-length array, the pointer can be NULL even though the dynamic
270 array has not entered the failure state. */
271_GL_ATTRIBUTE_NONNULL ((1))
272static inline DYNARRAY_ELEMENT *
273DYNARRAY_NAME (end) (struct DYNARRAY_STRUCT *list)
274{
275 return list->u.dynarray_header.array + list->u.dynarray_header.used;
276}
277
278/* Internal function. Slow path for the add function below. */
279static void
280DYNARRAY_NAME (add__) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)
281{
282 if (_GL_UNLIKELY
283 (!__libc_dynarray_emplace_enlarge (&list->u.dynarray_abstract,
284 DYNARRAY_SCRATCH (list),
285 sizeof (DYNARRAY_ELEMENT))))
286 {
287 DYNARRAY_NAME (mark_failed) (list);
288 return;
289 }
290
291 /* Copy the new element and increase the array length. */
292 list->u.dynarray_header.array[list->u.dynarray_header.used++] = item;
293}
294
295/* Add ITEM at the end of the array, enlarging it by one element.
296 Mark *LIST as failed if the dynamic array allocation size cannot be
297 increased. */
298_GL_ATTRIBUTE_NONNULL ((1))
299static inline void
300DYNARRAY_NAME (add) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)
301{
302 /* Do nothing in case of previous error. */
303 if (DYNARRAY_NAME (has_failed) (list))
304 return;
305
306 /* Enlarge the array if necessary. */
307 if (_GL_UNLIKELY (list->u.dynarray_header.used
308 == list->u.dynarray_header.allocated))
309 {
310 DYNARRAY_NAME (add__) (list, item);
311 return;
312 }
313
314 /* Copy the new element and increase the array length. */
315 list->u.dynarray_header.array[list->u.dynarray_header.used++] = item;
316}
317
318/* Internal function. Building block for the emplace functions below.
319 Assumes space for one more element in *LIST. */
320static inline DYNARRAY_ELEMENT *
321DYNARRAY_NAME (emplace__tail__) (struct DYNARRAY_STRUCT *list)
322{
323 DYNARRAY_ELEMENT *result
324 = &list->u.dynarray_header.array[list->u.dynarray_header.used];
325 ++list->u.dynarray_header.used;
326#if defined (DYNARRAY_ELEMENT_INIT)
327 DYNARRAY_ELEMENT_INIT (result);
328#elif defined (DYNARRAY_ELEMENT_FREE)
329 memset (result, 0, sizeof (*result));
330#endif
331 return result;
332}
333
334/* Internal function. Slow path for the emplace function below. */
335static DYNARRAY_ELEMENT *
336DYNARRAY_NAME (emplace__) (struct DYNARRAY_STRUCT *list)
337{
338 if (_GL_UNLIKELY
339 (!__libc_dynarray_emplace_enlarge (&list->u.dynarray_abstract,
340 DYNARRAY_SCRATCH (list),
341 sizeof (DYNARRAY_ELEMENT))))
342 {
343 DYNARRAY_NAME (mark_failed) (list);
344 return NULL;
345 }
346 return DYNARRAY_NAME (emplace__tail__) (list);
347}
348
349/* Allocate a place for a new element in *LIST and return a pointer to
350 it. The pointer can be NULL if the dynamic array cannot be
351 enlarged due to a memory allocation failure. */
352_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NODISCARD
353_GL_ATTRIBUTE_NONNULL ((1))
354static
355/* Avoid inlining with the larger initialization code. */
356#if !(defined (DYNARRAY_ELEMENT_INIT) || defined (DYNARRAY_ELEMENT_FREE))
357inline
358#endif
359DYNARRAY_ELEMENT *
360DYNARRAY_NAME (emplace) (struct DYNARRAY_STRUCT *list)
361{
362 /* Do nothing in case of previous error. */
363 if (DYNARRAY_NAME (has_failed) (list))
364 return NULL;
365
366 /* Enlarge the array if necessary. */
367 if (_GL_UNLIKELY (list->u.dynarray_header.used
368 == list->u.dynarray_header.allocated))
369 return (DYNARRAY_NAME (emplace__) (list));
370 return DYNARRAY_NAME (emplace__tail__) (list);
371}
372
373/* Change the size of *LIST to SIZE. If SIZE is larger than the
374 existing size, new elements are added (which can be initialized).
375 Otherwise, the list is truncated, and elements are freed. Return
376 false on memory allocation failure (and mark *LIST as failed). */
377_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NONNULL ((1))
378static bool
379DYNARRAY_NAME (resize) (struct DYNARRAY_STRUCT *list, size_t size)
380{
381 if (size > list->u.dynarray_header.used)
382 {
383 bool ok;
384#if defined (DYNARRAY_ELEMENT_INIT)
385 /* The new elements have to be initialized. */
386 size_t old_size = list->u.dynarray_header.used;
387 ok = __libc_dynarray_resize (&list->u.dynarray_abstract,
388 size, DYNARRAY_SCRATCH (list),
389 sizeof (DYNARRAY_ELEMENT));
390 if (ok)
391 for (size_t i = old_size; i < size; ++i)
392 {
393 DYNARRAY_ELEMENT_INIT (&list->u.dynarray_header.array[i]);
394 }
395#elif defined (DYNARRAY_ELEMENT_FREE)
396 /* Zero initialization is needed so that the elements can be
397 safely freed. */
398 ok = __libc_dynarray_resize_clear
399 (&list->u.dynarray_abstract, size,
400 DYNARRAY_SCRATCH (list), sizeof (DYNARRAY_ELEMENT));
401#else
402 ok = __libc_dynarray_resize (&list->u.dynarray_abstract,
403 size, DYNARRAY_SCRATCH (list),
404 sizeof (DYNARRAY_ELEMENT));
405#endif
406 if (_GL_UNLIKELY (!ok))
407 DYNARRAY_NAME (mark_failed) (list);
408 return ok;
409 }
410 else
411 {
412 /* The list has shrunk in size. Free the removed elements. */
413 DYNARRAY_NAME (free__elements__)
414 (list->u.dynarray_header.array + size,
415 list->u.dynarray_header.used - size);
416 list->u.dynarray_header.used = size;
417 return true;
418 }
419}
420
421/* Remove the last element of LIST if it is present. */
422_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NONNULL ((1))
423static void
424DYNARRAY_NAME (remove_last) (struct DYNARRAY_STRUCT *list)
425{
426 /* used > 0 implies that the array is the non-failed state. */
427 if (list->u.dynarray_header.used > 0)
428 {
429 size_t new_length = list->u.dynarray_header.used - 1;
430#ifdef DYNARRAY_ELEMENT_FREE
431 DYNARRAY_ELEMENT_FREE (&list->u.dynarray_header.array[new_length]);
432#endif
433 list->u.dynarray_header.used = new_length;
434 }
435}
436
437/* Remove all elements from the list. The elements are freed, but the
438 list itself is not. */
439_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NONNULL ((1))
440static void
441DYNARRAY_NAME (clear) (struct DYNARRAY_STRUCT *list)
442{
443 /* free__elements__ does nothing if the list is in the failed
444 state. */
445 DYNARRAY_NAME (free__elements__)
446 (list->u.dynarray_header.array, list->u.dynarray_header.used);
447 list->u.dynarray_header.used = 0;
448}
449
450#ifdef DYNARRAY_FINAL_TYPE
451/* Transfer the dynamic array to a permanent location at *RESULT.
452 Returns true on success on false on allocation failure. In either
453 case, *LIST is re-initialized and can be reused. A NULL pointer is
454 stored in *RESULT if LIST refers to an empty list. On success, the
455 pointer in *RESULT is heap-allocated and must be deallocated using
456 free. */
457_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NODISCARD
458_GL_ATTRIBUTE_NONNULL ((1, 2))
459static bool
460DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list,
461 DYNARRAY_FINAL_TYPE *result)
462{
463 struct dynarray_finalize_result res;
464 if (__libc_dynarray_finalize (&list->u.dynarray_abstract,
465 DYNARRAY_SCRATCH (list),
466 sizeof (DYNARRAY_ELEMENT), &res))
467 {
468 /* On success, the result owns all the data. */
469 DYNARRAY_NAME (init) (list);
470 *result = (DYNARRAY_FINAL_TYPE) { res.array, res.length };
471 return true;
472 }
473 else
474 {
475 /* On error, we need to free all data. */
476 DYNARRAY_FREE (list);
477 errno = ENOMEM;
478 return false;
479 }
480}
481#else /* !DYNARRAY_FINAL_TYPE */
482/* Transfer the dynamic array to a heap-allocated array and return a
483 pointer to it. The pointer is NULL if memory allocation fails, or
484 if the array is empty, so this function should be used only for
485 arrays which are known not be empty (usually because they always
486 have a sentinel at the end). If LENGTHP is not NULL, the array
487 length is written to *LENGTHP. *LIST is re-initialized and can be
488 reused. */
489_GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_NODISCARD
490_GL_ATTRIBUTE_NONNULL ((1))
491static DYNARRAY_ELEMENT *
492DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list, size_t *lengthp)
493{
494 struct dynarray_finalize_result res;
495 if (__libc_dynarray_finalize (&list->u.dynarray_abstract,
496 DYNARRAY_SCRATCH (list),
497 sizeof (DYNARRAY_ELEMENT), &res))
498 {
499 /* On success, the result owns all the data. */
500 DYNARRAY_NAME (init) (list);
501 if (lengthp != NULL)
502 *lengthp = res.length;
503 return res.array;
504 }
505 else
506 {
507 /* On error, we need to free all data. */
508 DYNARRAY_FREE (list);
509 errno = ENOMEM;
510 return NULL;
511 }
512}
513#endif /* !DYNARRAY_FINAL_TYPE */
514
515/* Undo macro definitions. */
516
517#undef DYNARRAY_CONCAT0
518#undef DYNARRAY_CONCAT1
519#undef DYNARRAY_NAME
520#undef DYNARRAY_SCRATCH
521#undef DYNARRAY_HAVE_SCRATCH
522
523#undef DYNARRAY_STRUCT
524#undef DYNARRAY_ELEMENT
525#undef DYNARRAY_PREFIX
526#undef DYNARRAY_ELEMENT_FREE
527#undef DYNARRAY_ELEMENT_INIT
528#undef DYNARRAY_INITIAL_SIZE
529#undef DYNARRAY_FINAL_TYPE
diff --git a/gl/malloc/dynarray.gl.h b/gl/malloc/dynarray.gl.h
new file mode 100644
index 0000000..8227362
--- /dev/null
+++ b/gl/malloc/dynarray.gl.h
@@ -0,0 +1,174 @@
1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2/* Type-safe arrays which grow dynamically. Shared definitions.
3 Copyright (C) 2017-2021 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20/* To use the dynarray facility, you need to include
21 <malloc/dynarray-skeleton.c> and define the parameter macros
22 documented in that file.
23
24 A minimal example which provides a growing list of integers can be
25 defined like this:
26
27 struct int_array
28 {
29 // Pointer to result array followed by its length,
30 // as required by DYNARRAY_FINAL_TYPE.
31 int *array;
32 size_t length;
33 };
34
35 #define DYNARRAY_STRUCT dynarray_int
36 #define DYNARRAY_ELEMENT int
37 #define DYNARRAY_PREFIX dynarray_int_
38 #define DYNARRAY_FINAL_TYPE struct int_array
39 #include <malloc/dynarray-skeleton.c>
40
41 To create a three-element array with elements 1, 2, 3, use this
42 code:
43
44 struct dynarray_int dyn;
45 dynarray_int_init (&dyn);
46 for (int i = 1; i <= 3; ++i)
47 {
48 int *place = dynarray_int_emplace (&dyn);
49 assert (place != NULL);
50 *place = i;
51 }
52 struct int_array result;
53 bool ok = dynarray_int_finalize (&dyn, &result);
54 assert (ok);
55 assert (result.length == 3);
56 assert (result.array[0] == 1);
57 assert (result.array[1] == 2);
58 assert (result.array[2] == 3);
59 free (result.array);
60
61 If the elements contain resources which must be freed, define
62 DYNARRAY_ELEMENT_FREE appropriately, like this:
63
64 struct str_array
65 {
66 char **array;
67 size_t length;
68 };
69
70 #define DYNARRAY_STRUCT dynarray_str
71 #define DYNARRAY_ELEMENT char *
72 #define DYNARRAY_ELEMENT_FREE(ptr) free (*ptr)
73 #define DYNARRAY_PREFIX dynarray_str_
74 #define DYNARRAY_FINAL_TYPE struct str_array
75 #include <malloc/dynarray-skeleton.c>
76
77 Compared to scratch buffers, dynamic arrays have the following
78 features:
79
80 - They have an element type, and are not just an untyped buffer of
81 bytes.
82
83 - When growing, previously stored elements are preserved. (It is
84 expected that scratch_buffer_grow_preserve and
85 scratch_buffer_set_array_size eventually go away because all
86 current users are moved to dynamic arrays.)
87
88 - Scratch buffers have a more aggressive growth policy because
89 growing them typically means a retry of an operation (across an
90 NSS service module boundary), which is expensive.
91
92 - For the same reason, scratch buffers have a much larger initial
93 stack allocation. */
94
95#ifndef _DYNARRAY_H
96#define _DYNARRAY_H
97
98#include <stdbool.h>
99#include <stddef.h>
100#include <string.h>
101
102struct dynarray_header
103{
104 size_t used;
105 size_t allocated;
106 void *array;
107};
108
109/* Marker used in the allocated member to indicate that an error was
110 encountered. */
111static inline size_t
112__dynarray_error_marker (void)
113{
114 return -1;
115}
116
117/* Internal function. See the has_failed function in
118 dynarray-skeleton.c. */
119static inline bool
120__dynarray_error (struct dynarray_header *list)
121{
122 return list->allocated == __dynarray_error_marker ();
123}
124
125/* Internal function. Enlarge the dynamically allocated area of the
126 array to make room for one more element. SCRATCH is a pointer to
127 the scratch area (which is not heap-allocated and must not be
128 freed). ELEMENT_SIZE is the size, in bytes, of one element.
129 Return false on failure, true on success. */
130bool __libc_dynarray_emplace_enlarge (struct dynarray_header *,
131 void *scratch, size_t element_size);
132
133/* Internal function. Enlarge the dynamically allocated area of the
134 array to make room for at least SIZE elements (which must be larger
135 than the existing used part of the dynamic array). SCRATCH is a
136 pointer to the scratch area (which is not heap-allocated and must
137 not be freed). ELEMENT_SIZE is the size, in bytes, of one element.
138 Return false on failure, true on success. */
139bool __libc_dynarray_resize (struct dynarray_header *, size_t size,
140 void *scratch, size_t element_size);
141
142/* Internal function. Like __libc_dynarray_resize, but clear the new
143 part of the dynamic array. */
144bool __libc_dynarray_resize_clear (struct dynarray_header *, size_t size,
145 void *scratch, size_t element_size);
146
147/* Internal type. */
148struct dynarray_finalize_result
149{
150 void *array;
151 size_t length;
152};
153
154/* Internal function. Copy the dynamically-allocated area to an
155 explicitly-sized heap allocation. SCRATCH is a pointer to the
156 embedded scratch space. ELEMENT_SIZE is the size, in bytes, of the
157 element type. On success, true is returned, and pointer and length
158 are written to *RESULT. On failure, false is returned. The caller
159 has to take care of some of the memory management; this function is
160 expected to be called from dynarray-skeleton.c. */
161bool __libc_dynarray_finalize (struct dynarray_header *list, void *scratch,
162 size_t element_size,
163 struct dynarray_finalize_result *result);
164
165
166/* Internal function. Terminate the process after an index error.
167 SIZE is the number of elements of the dynamic array. INDEX is the
168 lookup index which triggered the failure. */
169_Noreturn void __libc_dynarray_at_failure (size_t size, size_t index);
170
171#ifndef _ISOMAC
172#endif
173
174#endif /* _DYNARRAY_H */