NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
atoi.c
Go to the documentation of this file.
1
23
29
30
#include "config.h"
31
#include <errno.h>
32
#include <limits.h>
33
#include <stdlib.h>
34
#include "
atoi.h
"
35
53
static
const
char
*
str_atol_clamp
(
const
char
*str,
long
*dst,
long
lmin,
long
lmax)
54
{
55
if
(dst)
56
{
57
*dst = 0;
58
}
59
60
if
(!str || (*str ==
'\0'
))
61
{
62
return
NULL;
63
}
64
65
char
*e = NULL;
66
errno = 0;
67
long
res = strtol(str, &e, 10);
68
if
((e == str) || (((res == LONG_MIN) || (res == LONG_MAX)) && (errno == ERANGE)) ||
69
(res < lmin) || (res > lmax))
70
{
71
return
NULL;
72
}
73
74
if
(dst)
75
{
76
*dst = res;
77
}
78
79
return
e;
80
}
81
98
static
const
char
*
str_atoull_clamp
(
const
char
*str,
unsigned
long
long
*dst,
99
unsigned
long
long
ullmax)
100
{
101
if
(dst)
102
{
103
*dst = 0;
104
}
105
106
if
(!str || (*str ==
'\0'
))
107
{
108
return
str;
109
}
110
111
char
*e = NULL;
112
errno = 0;
113
unsigned
long
long
res = strtoull(str, &e, 10);
114
if
((e == str) || ((res == ULLONG_MAX) && (errno == ERANGE)) || (res > ullmax))
115
{
116
return
NULL;
117
}
118
119
if
(dst)
120
{
121
*dst = res;
122
}
123
124
return
e;
125
}
126
142
const
char
*
mutt_str_atol
(
const
char
*str,
long
*dst)
143
{
144
return
str_atol_clamp
(str, dst, LONG_MIN, LONG_MAX);
145
}
146
164
const
char
*
mutt_str_atos
(
const
char
*str,
short
*dst)
165
{
166
long
l = 0;
167
const
char
*res =
str_atol_clamp
(str, &l, SHRT_MIN, SHRT_MAX);
168
if
(dst)
169
{
170
*dst = res ? l : 0;
171
}
172
return
res;
173
}
174
191
const
char
*
mutt_str_atoi
(
const
char
*str,
int
*dst)
192
{
193
long
l = 0;
194
const
char
*res =
str_atol_clamp
(str, &l, INT_MIN, INT_MAX);
195
if
(dst)
196
{
197
*dst = res ? l : 0;
198
}
199
return
res;
200
}
201
217
const
char
*
mutt_str_atoui
(
const
char
*str,
unsigned
int
*dst)
218
{
219
unsigned
long
long
l = 0;
220
const
char
*res =
str_atoull_clamp
(str, &l, UINT_MAX);
221
if
(dst)
222
{
223
*dst = res ? l : 0;
224
}
225
return
res;
226
}
227
243
const
char
*
mutt_str_atoul
(
const
char
*str,
unsigned
long
*dst)
244
{
245
unsigned
long
long
l = 0;
246
const
char
*res =
str_atoull_clamp
(str, &l, ULONG_MAX);
247
if
(dst)
248
{
249
*dst = res ? l : 0;
250
}
251
return
res;
252
}
253
269
const
char
*
mutt_str_atous
(
const
char
*str,
unsigned
short
*dst)
270
{
271
unsigned
long
long
l = 0;
272
const
char
*res =
str_atoull_clamp
(str, &l, USHRT_MAX);
273
if
(dst)
274
{
275
*dst = res ? l : 0;
276
}
277
return
res;
278
}
279
295
const
char
*
mutt_str_atoull
(
const
char
*str,
unsigned
long
long
*dst)
296
{
297
return
str_atoull_clamp
(str, dst, ULLONG_MAX);
298
}
str_atol_clamp
static const char * str_atol_clamp(const char *str, long *dst, long lmin, long lmax)
Convert ASCII string to a long and clamp.
Definition
atoi.c:53
mutt_str_atoull
const char * mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition
atoi.c:295
mutt_str_atous
const char * mutt_str_atous(const char *str, unsigned short *dst)
Convert ASCII string to an unsigned short.
Definition
atoi.c:269
mutt_str_atol
const char * mutt_str_atol(const char *str, long *dst)
Convert ASCII string to a long.
Definition
atoi.c:142
mutt_str_atoul
const char * mutt_str_atoul(const char *str, unsigned long *dst)
Convert ASCII string to an unsigned long.
Definition
atoi.c:243
str_atoull_clamp
static const char * str_atoull_clamp(const char *str, unsigned long long *dst, unsigned long long ullmax)
Convert ASCII string to an unsigned long long and clamp.
Definition
atoi.c:98
mutt_str_atos
const char * mutt_str_atos(const char *str, short *dst)
Convert ASCII string to a short.
Definition
atoi.c:164
mutt_str_atoui
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition
atoi.c:217
mutt_str_atoi
const char * mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition
atoi.c:191
atoi.h
Parse a number in a string.