aboutsummaryrefslogtreecommitdiffstats
path: root/libsimple/strtoint.h
blob: d7fc292f40e8578739f7e9a6118270bcc525675b (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* See LICENSE file for copyright and license details. */


/**
 * Converts a string to a `signed char`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
signed char libsimple_strtohh(const char *restrict, char **restrict, int);
#ifndef strtohh
# define strtohh libsimple_strtohh
#endif


/**
 * Converts a string to a `unsigned char`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
unsigned char libsimple_strtouhh(const char *restrict, char **restrict, int);
#ifndef strtouhh
# define strtouhh libsimple_strtouhh
#endif


/**
 * Converts a string to a `signed short int`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
signed short int libsimple_strtoh(const char *restrict, char **restrict, int);
#ifndef strtoh
# define strtoh libsimple_strtoh
#endif


/**
 * Converts a string to a `unsigned short int`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
unsigned short int libsimple_strtouh(const char *restrict, char **restrict, int);
#ifndef strtouh
# define strtouh libsimple_strtouh
#endif


/**
 * Converts a string to a `signed int`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
signed int libsimple_strtoi(const char *restrict, char **restrict, int);
#ifndef strtoi
# define strtoi libsimple_strtoi
#endif


/**
 * Converts a string to a `unsigned int`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
unsigned int libsimple_strtou(const char *restrict, char **restrict, int);
#ifndef strtou
# define strtou libsimple_strtou
#endif


/**
 * Converts a string to a `ssize_t`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
inline ssize_t
libsimple_strtoz(const char *restrict nptr__, char **restrict endptr__, int base__)
{
	return (ssize_t)strtol(nptr__, endptr__, base__);
}
#ifndef strtoz
# define strtoz libsimple_strtoz
#endif


/**
 * Converts a string to a `size_t`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
inline size_t
libsimple_strtouz(const char *restrict nptr__, char **restrict endptr__, int base__)
{
	return (size_t)strtoul(nptr__, endptr__, base__);
}
#ifndef strtouz
# define strtouz libsimple_strtouz
#endif


/**
 * Converts a string to a `int8_t`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
int_least8_t libsimple_strtoi8(const char *restrict, char **restrict, int);
#ifndef strtoi8
# define strtoi8 libsimple_strtoi8
#endif


/**
 * Converts a string to a `uint8_t`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
uint_least8_t libsimple_strtou8(const char *restrict, char **restrict, int);
#ifndef strtou8
# define strtou8 libsimple_strtou8
#endif


/**
 * Converts a string to a `int16_t`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
int_least16_t libsimple_strtoi16(const char *restrict, char **restrict, int);
#ifndef strtoi16
# define strtoi16 libsimple_strtoi16
#endif


/**
 * Converts a string to a `uint16_t`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
uint_least16_t libsimple_strtou16(const char *restrict, char **restrict, int);
#ifndef strtou16
# define strtou16 libsimple_strtou16
#endif


/**
 * Converts a string to a `int32_t`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
int_least32_t libsimple_strtoi32(const char *restrict, char **restrict, int);
#ifndef strtoi32
# define strtoi32 libsimple_strtoi32
#endif


/**
 * Converts a string to a `uint32_t`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
uint_least32_t libsimple_strtou32(const char *restrict, char **restrict, int);
#ifndef strtou32
# define strtou32 libsimple_strtou32
#endif


/**
 * Converts a string to a `int64_t`
 * according to the rules of strtol(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
int_least64_t libsimple_strtoi64(const char *restrict, char **restrict, int);
#ifndef strtoi64
# define strtoi64 libsimple_strtoi64
#endif


/**
 * Converts a string to a `uint64_t`
 * according to the rules of strtoul(3)
 * 
 * @param   nptr    The string to parse
 * @param   endptr  Output parameter for the position in `nptr`
 *                  where the first character that is not part
 *                  of the interpreted value resides
 * @param   base    The base the value is encoded in, 0 if
 *                  the function shall accept a prefix to
 *                  specify the base if it is not 10
 * @return          The encoded value (`errno` is unchanges), or
 *                  if out of range (`errno` set to `ERANGE`), the
 *                  closed value that can be represented; 0 on
 *                  failure (unless `errno` not set to `ERANGE`)
 */
LIBSIMPLE_GCC_ONLY__(__attribute__((__nonnull__(1), __warn_unused_result__)))
uint_least64_t libsimple_strtou64(const char *restrict, char **restrict, int);
#ifndef strtou64
# define strtou64 libsimple_strtou64
#endif