Debian Codegraph @

lib/printf-args.h

raw
1 /* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2024 Free Software
3 Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 #ifndef _PRINTF_ARGS_H
19 #define _PRINTF_ARGS_H
20
21 /* This file can be parametrized with the following macros:
22 ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
23 PRINTF_FETCHARGS Name of the function to be declared.
24 STATIC Set to 'static' to declare the function static. */
25
26 /* Default parameters. */
27 #ifndef PRINTF_FETCHARGS
28 # define PRINTF_FETCHARGS printf_fetchargs
29 #endif
30
31 /* Get size_t, wchar_t. */
32 #include <stddef.h>
33
34 /* Get wint_t. */
35 #if HAVE_WINT_T
36 # include <wchar.h>
37 #endif
38
39 /* Get intN_t, uintN_t, intN_fast_t, uintN_fast_t. */
40 #include <stdint.h>
41
42 /* Get va_list. */
43 #include <stdarg.h>
44
45
46 /* Argument types */
47 typedef enum
48 {
49 TYPE_NONE,
50 TYPE_SCHAR,
51 TYPE_UCHAR,
52 TYPE_SHORT,
53 TYPE_USHORT,
54 TYPE_INT,
55 TYPE_UINT,
56 TYPE_LONGINT,
57 TYPE_ULONGINT,
58 TYPE_LONGLONGINT,
59 TYPE_ULONGLONGINT,
60 /* According to ISO C 23 ยง 7.23.6.1, "all exact-width integer types",
61 "all minimum-width integer types", and "all fastest minimum-width integer
62 types" defined in <stdint.h> should be supported. But for portability
63 between platforms, we support only those with N = 8, 16, 32, 64. */
64 TYPE_INT8_T,
65 TYPE_UINT8_T,
66 TYPE_INT16_T,
67 TYPE_UINT16_T,
68 TYPE_INT32_T,
69 TYPE_UINT32_T,
70 TYPE_INT64_T,
71 TYPE_UINT64_T,
72 TYPE_INT_FAST8_T,
73 TYPE_UINT_FAST8_T,
74 TYPE_INT_FAST16_T,
75 TYPE_UINT_FAST16_T,
76 TYPE_INT_FAST32_T,
77 TYPE_UINT_FAST32_T,
78 TYPE_INT_FAST64_T,
79 TYPE_UINT_FAST64_T,
80 TYPE_DOUBLE,
81 TYPE_LONGDOUBLE,
82 TYPE_CHAR,
83 #if HAVE_WINT_T
84 TYPE_WIDE_CHAR,
85 #endif
86 TYPE_STRING,
87 TYPE_WIDE_STRING,
88 TYPE_POINTER,
89 TYPE_COUNT_SCHAR_POINTER,
90 TYPE_COUNT_SHORT_POINTER,
91 TYPE_COUNT_INT_POINTER,
92 TYPE_COUNT_LONGINT_POINTER,
93 TYPE_COUNT_LONGLONGINT_POINTER,
94 TYPE_COUNT_INT8_T_POINTER,
95 TYPE_COUNT_INT16_T_POINTER,
96 TYPE_COUNT_INT32_T_POINTER,
97 TYPE_COUNT_INT64_T_POINTER,
98 TYPE_COUNT_INT_FAST8_T_POINTER,
99 TYPE_COUNT_INT_FAST16_T_POINTER,
100 TYPE_COUNT_INT_FAST32_T_POINTER,
101 TYPE_COUNT_INT_FAST64_T_POINTER
102 #if ENABLE_UNISTDIO
103 /* The unistdio extensions. */
104 , TYPE_U8_STRING
105 , TYPE_U16_STRING
106 , TYPE_U32_STRING
107 #endif
108 } arg_type;
109
110 /* Polymorphic argument */
111 typedef struct
112 {
113 arg_type type;
114 union
115 {
116 signed char a_schar;
117 unsigned char a_uchar;
118 short a_short;
119 unsigned short a_ushort;
120 int a_int;
121 unsigned int a_uint;
122 long int a_longint;
123 unsigned long int a_ulongint;
124 long long int a_longlongint;
125 unsigned long long int a_ulonglongint;
126 int8_t a_int8_t;
127 uint8_t a_uint8_t;
128 int16_t a_int16_t;
129 uint16_t a_uint16_t;
130 int32_t a_int32_t;
131 uint32_t a_uint32_t;
132 int64_t a_int64_t;
133 uint64_t a_uint64_t;
134 int_fast8_t a_int_fast8_t;
135 uint_fast8_t a_uint_fast8_t;
136 int_fast16_t a_int_fast16_t;
137 uint_fast16_t a_uint_fast16_t;
138 int_fast32_t a_int_fast32_t;
139 uint_fast32_t a_uint_fast32_t;
140 int_fast64_t a_int_fast64_t;
141 uint_fast64_t a_uint_fast64_t;
142 float a_float; /* unused */
143 double a_double;
144 long double a_longdouble;
145 int a_char;
146 #if HAVE_WINT_T
147 wint_t a_wide_char;
148 #endif
149 const char* a_string;
150 const wchar_t* a_wide_string;
151 void* a_pointer;
152 signed char * a_count_schar_pointer;
153 short * a_count_short_pointer;
154 int * a_count_int_pointer;
155 long int * a_count_longint_pointer;
156 long long int * a_count_longlongint_pointer;
157 int8_t * a_count_int8_t_pointer;
158 int16_t * a_count_int16_t_pointer;
159 int32_t * a_count_int32_t_pointer;
160 int64_t * a_count_int64_t_pointer;
161 int_fast8_t * a_count_int_fast8_t_pointer;
162 int_fast16_t * a_count_int_fast16_t_pointer;
163 int_fast32_t * a_count_int_fast32_t_pointer;
164 int_fast64_t * a_count_int_fast64_t_pointer;
165 #if ENABLE_UNISTDIO
166 /* The unistdio extensions. */
167 const uint8_t * a_u8_string;
168 const uint16_t * a_u16_string;
169 const uint32_t * a_u32_string;
170 #endif
171 }
172 a;
173 }
174 argument;
175
176 /* Number of directly allocated arguments (no malloc() needed). */
177 #define N_DIRECT_ALLOC_ARGUMENTS 7
178
179 typedef struct
180 {
181 size_t count;
182 argument *arg;
183 argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
184 }
185 arguments;
186
187
188 /* Fetch the arguments, putting them into a. */
189 #ifdef STATIC
190 STATIC
191 #else
192 extern
193 #endif
194 int PRINTF_FETCHARGS (va_list args, arguments *a);
195
196 #endif /* _PRINTF_ARGS_H */