summaryrefslogtreecommitdiffstats
path: root/include/a2i/a2i.h
blob: 5d4e1a81f13af548ed88a3eb294f8703ef68da86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: LGPL-3.0-only WITH LGPL-3.0-linking-exception


#ifndef INCLUDE_A2I_A2I_H_
#define INCLUDE_A2I_A2I_H_


#include <a2i/a2i_func.h>  // IWYU pragma: keep


#define a2i(TYPE, n, s, endp, ...)                                            \
(                                                                             \
	_Generic((void (*)(TYPE, typeof(endp))) 0,                            \
		void (*)(signed char,        const char **):  a2shh_c,        \
		void (*)(signed char,        char **):        a2shh_nc,       \
		void (*)(signed char,        void *):         a2shh_nc,       \
		void (*)(short,              const char **):  a2sh_c,         \
		void (*)(short,              char **):        a2sh_nc,        \
		void (*)(short,              void *):         a2sh_nc,        \
		void (*)(int,                const char **):  a2si_c,         \
		void (*)(int,                char **):        a2si_nc,        \
		void (*)(int,                void *):         a2si_nc,        \
		void (*)(long,               const char **):  a2sl_c,         \
		void (*)(long,               char **):        a2sl_nc,        \
		void (*)(long,               void *):         a2sl_nc,        \
		void (*)(long long,          const char **):  a2sll_c,        \
		void (*)(long long,          char **):        a2sll_nc,       \
		void (*)(long long,          void *):         a2sll_nc,       \
		void (*)(unsigned char,      const char **):  a2uhh_c,        \
		void (*)(unsigned char,      char **):        a2uhh_nc,       \
		void (*)(unsigned char,      void *):         a2uhh_nc,       \
		void (*)(unsigned short,     const char **):  a2uh_c,         \
		void (*)(unsigned short,     char **):        a2uh_nc,        \
		void (*)(unsigned short,     void *):         a2uh_nc,        \
		void (*)(unsigned int,       const char **):  a2ui_c,         \
		void (*)(unsigned int,       char **):        a2ui_nc,        \
		void (*)(unsigned int,       void *):         a2ui_nc,        \
		void (*)(unsigned long,      const char **):  a2ul_c,         \
		void (*)(unsigned long,      char **):        a2ul_nc,        \
		void (*)(unsigned long,      void *):         a2ul_nc,        \
		void (*)(unsigned long long, const char **):  a2ull_c,        \
		void (*)(unsigned long long, char **):        a2ull_nc,       \
		void (*)(unsigned long long, void *):         a2ull_nc        \
	)(n, s, endp, __VA_ARGS__)                                            \
)


#define a2s(TYPE, n, s, endp, ...)                                            \
(                                                                             \
	_Generic((void (*)(TYPE, typeof(endp))) 0,                            \
		void (*)(signed char,        const char **):  a2shh_c,        \
		void (*)(signed char,        char **):        a2shh_nc,       \
		void (*)(signed char,        void *):         a2shh_nc,       \
		void (*)(short,              const char **):  a2sh_c,         \
		void (*)(short,              char **):        a2sh_nc,        \
		void (*)(short,              void *):         a2sh_nc,        \
		void (*)(int,                const char **):  a2si_c,         \
		void (*)(int,                char **):        a2si_nc,        \
		void (*)(int,                void *):         a2si_nc,        \
		void (*)(long,               const char **):  a2sl_c,         \
		void (*)(long,               char **):        a2sl_nc,        \
		void (*)(long,               void *):         a2sl_nc,        \
		void (*)(long long,          const char **):  a2sll_c,        \
		void (*)(long long,          char **):        a2sll_nc,       \
		void (*)(long long,          void *):         a2sll_nc        \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2u(TYPE, n, s, endp, ...)                                            \
(                                                                             \
	_Generic((void (*)(TYPE, typeof(endp))) 0,                            \
		void (*)(unsigned char,      const char **):  a2uhh_c,        \
		void (*)(unsigned char,      char **):        a2uhh_nc,       \
		void (*)(unsigned char,      void *):         a2uhh_nc,       \
		void (*)(unsigned short,     const char **):  a2uh_c,         \
		void (*)(unsigned short,     char **):        a2uh_nc,        \
		void (*)(unsigned short,     void *):         a2uh_nc,        \
		void (*)(unsigned int,       const char **):  a2ui_c,         \
		void (*)(unsigned int,       char **):        a2ui_nc,        \
		void (*)(unsigned int,       void *):         a2ui_nc,        \
		void (*)(unsigned long,      const char **):  a2ul_c,         \
		void (*)(unsigned long,      char **):        a2ul_nc,        \
		void (*)(unsigned long,      void *):         a2ul_nc,        \
		void (*)(unsigned long long, const char **):  a2ull_c,        \
		void (*)(unsigned long long, char **):        a2ull_nc,       \
		void (*)(unsigned long long, void *):         a2ull_nc        \
	)(n, s, endp, __VA_ARGS__)                                            \
)


#define a2shh(n, s, endp, ...)                                                \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2shh_c,                                      \
		char **:        a2shh_nc,                                     \
		void *:         a2shh_nc                                      \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2sh(n, s, endp, ...)                                                 \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2sh_c,                                       \
		char **:        a2sh_nc,                                      \
		void *:         a2sh_nc                                       \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2si(n, s, endp, ...)                                                 \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2si_c,                                       \
		char **:        a2si_nc,                                      \
		void *:         a2si_nc                                       \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2sl(n, s, endp, ...)                                                 \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2sl_c,                                       \
		char **:        a2sl_nc,                                      \
		void *:         a2sl_nc                                       \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2sll(n, s, endp, ...)                                                \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2sll_c,                                      \
		char **:        a2sll_nc,                                     \
		void *:         a2sll_nc                                      \
	)(n, s, endp, __VA_ARGS__)                                            \
)


#define a2uhh(n, s, endp, ...)                                                \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2uhh_c,                                      \
		char **:        a2uhh_nc,                                     \
		void *:         a2uhh_nc                                      \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2uh(n, s, endp, ...)                                                 \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2uh_c,                                       \
		char **:        a2uh_nc,                                      \
		void *:         a2uh_nc                                       \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2ui(n, s, endp, ...)                                                 \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2ui_c,                                       \
		char **:        a2ui_nc,                                      \
		void *:         a2ui_nc                                       \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2ul(n, s, endp, ...)                                                 \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2ul_c,                                       \
		char **:        a2ul_nc,                                      \
		void *:         a2ul_nc                                       \
	)(n, s, endp, __VA_ARGS__)                                            \
)

#define a2ull(n, s, endp, ...)                                                \
(                                                                             \
	_Generic(endp,                                                        \
		const char **:  a2ull_c,                                      \
		char **:        a2ull_nc,                                     \
		void *:         a2ull_nc                                      \
	)(n, s, endp, __VA_ARGS__)                                            \
)


#endif  // include guard