-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstrton.3
261 lines (261 loc) · 4.42 KB
/
strton.3
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
.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX \" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS
.PD 0
.ft 5
.nf
..
.de EE \" end example
.fi
.ft
.PD
.RE
.PP
..
.TH STRTON 3
.SH NAME
.BR strton ,
.B strtonll
\- convert string to integer with optional pseudo-float support
.SH SYNOPSIS
.L "long strton(const char* s, char** e, char *basep, int m)"
.PP
.L "intmax_t strtonll(const char* s, char** e, char *basep, int m)"
.SH DESCRIPTION
The
.B strton
and
.B strtonll
functions convert the zero-terminated string
.I s
to a
.B long
integer or an
.B intmax_t
integer, respectively.
If
.I e
is not
.LR NULL ,
then
.I *e
is set to point to the first unrecognized character in
.IR s ,
or to its terminating zero byte if the conversion was fully successful.
Leading
.IR isspace (3)
characters in
.I s
are skipped over and ignored.
.PP
A number is composed of
.IR sign \- base \- number \- suffix .
All but
.I number
are optional. The
.I sign
may be
.L +
or
.LR - .
The
.I base
may be
.B 0x
for hexadecimal,
.B 0
for octal, or
\f2nn\fP\f3#\fP
for base
2 \[<=]
.I nn
\[<=] 64.
.PP
For bases greater than 10, the digits above 9 are represented
by the lower case letters, the upper case letters,
.RL \[lq] @ \[rq],
and
.RL \[lq] _ \[rq],
respectively.
For bases less than or equal to 36, upper and lower case
letters can be used interchangeably.
.PP
If the string
.I s
has a
.I base
prefix. then the numeric value of the base detected is stored in
.IR *basep ,
which may affect subsequent calls.
If, on entry,
.I basep
is not
.L NULL
and the numeric value of
.I *basep
is not zero,
then the conversion is done
from the base specified in
.IR basep ,
and the
.I base
prefix is not recognized.
.PP
A case-insensitive
.IR suffix
may be specified in
.I s
if the base prefix is omitted.
It multiplies the converted number and may be
.B b
for block (512),
or one of the SI unit prefixes
.B k
for kilo (1000),
.B M
for mega (1000 \(mu 1000),
.B G
for giga (1000 \(mu 1000 \(mu 1000),
and so on for
.B T
(tera),
.B P
(peta), and
.B E
(exa),
or one of the IEC power-of-two prefixes
.B Ki
for kibi (1024),
.B Mi
for mebi (1024 \(mu 1024),
.B Gi
for gibi (1024 \(mu 1024 \(mu 1024),
and so on for
.B Ti
(tebi),
.B Pi
(pebi), and
.B Ei
(exbi).
The SI and IEC suffixes may optionally have a final
.B B
(i.e., bytes) added, which is accepted and ignored.
.PP
The
.I m
parameter may also be used to specify a multiplier.
If neither a
.I base
prefix nor a multiplier
.I suffix
is supplied in
.IR s ,
and
.I *basep
is 0,
and a value greater than 1 is specified in the
.I m
parameter, then the converted value will be multiplied by
.IR m .
.PP
Additionally, the
.I m
parameter may be used to support pseudo-floating point numbers. If
.I m
is greater than 1,
and the
.I suffix
consists of the currently set locale's radix point (by default,
.RL \[lq] . \[rq]),
followed by decimal digits, then
.I s
is treated as if it were a floating point number
which is multiplied by
.IR m .
For example, an
.I s
string value of
.L \[dq]12.34\[dq]
combined with an
.I m
value of 1000 yields an integer result of 12340.
.PP
A negative
.I m
disables the recognition of any
.IR suffix .
Otherwise, if neither case above applies,
.I m
is ignored.
.SH "RETURN VALUES"
The
.B strton
and
.B strtonll
functions return the value that represents the conversion of
zero or more recognized characters in the string
.I s
up to the first unrecognized character or the terminating zero byte.
The address of the first unrecognized character,
or the terminating zero byte,
is stored in
.I *e
if
.I e
is not
.LR NULL .
Note that
.I errno
is not changed in this case.
.PP
If the specified base is less than 2 or greater than 64, then
.I *e
is set to
.I s
(if
.I e
is not
.LR NULL ),
the global variable
.I errno
is set to
.LR EINVAL ,
and 0 is returned.
.PP
If an overflow or underflow occurs, then
.I errno
is set to
.L ERANGE
and the return value is the function's integer type's
maximum possible or minimum possible value, respectively.
.SH "SEE ALSO"
.IR atoi (3),
.IR scanf (3),
.IR setlocale (3),
.IR strtol (3),
.IR strtoul (3),
.IR strtod (3)