iwm: Fix S:N reporting in ifconfig(8)
[dragonfly.git] / lib / libc / stdlib / strtoul.3
1 .\" Copyright (c) 1990, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)strtoul.3   8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/stdlib/strtoul.3,v 1.23 2007/01/09 00:28:10 imp Exp $
34 .\"
35 .Dd December 25, 2013
36 .Dt STRTOUL 3
37 .Os
38 .Sh NAME
39 .Nm strtoul ,
40 .Nm strtoul_l ,
41 .Nm strtoull ,
42 .Nm strtoull_l ,
43 .Nm strtoumax ,
44 .Nm strtoumax_l ,
45 .Nm strtouq
46 .Nd "convert a string to an"
47 .Vt "unsigned long" , "unsigned long long" , uintmax_t ,
48 or
49 .Vt u_quad_t
50 integer
51 .Sh LIBRARY
52 .Lb libc
53 .Sh SYNOPSIS
54 .In stdlib.h
55 .In limits.h
56 .Ft "unsigned long"
57 .Fn strtoul "const char * restrict nptr" "char ** restrict endptr" "int base"
58 .Ft "unsigned long long"
59 .Fn strtoull "const char * restrict nptr" "char ** restrict endptr" "int base"
60 .In inttypes.h
61 .Ft uintmax_t
62 .Fn strtoumax "const char * restrict nptr" "char ** restrict endptr" "int base"
63 .In sys/types.h
64 .Ft u_quad_t
65 .Fn strtouq "const char *nptr" "char **endptr" "int base"
66 .In xlocale.h
67 .Ft "unsigned long"
68 .Fn strtoul_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t locale"
69 .Ft "unsigned long long"
70 .Fn strtoull_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t locale"
71 .Ft uintmax_t
72 .Fn strtoumax_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t locale"
73 .Sh DESCRIPTION
74 The
75 .Fn strtoul
76 and
77 .Fn strtoul_l
78 functions convert the string in
79 .Fa nptr
80 to an
81 .Vt "unsigned long"
82 value.
83 The
84 .Fn strtoull
85 and
86 .Fn strtoull_l
87 functions convert the string in
88 .Fa nptr
89 to an
90 .Vt "unsigned long long"
91 value.
92 The
93 .Fn strtoumax
94 and
95 .Fn strtoumax_l
96 functions convert the string in
97 .Fa nptr
98 to an
99 .Vt uintmax_t
100 value.
101 The
102 .Fn strtouq
103 function
104 converts the string in
105 .Fa nptr
106 to a
107 .Vt u_quad_t
108 value.
109 The conversion is done according to the given
110 .Fa base ,
111 which must be between 2 and 36 inclusive,
112 or be the special value 0.
113 .Pp
114 The string may begin with an arbitrary amount of white space
115 (as determined by
116 .Xr isspace 3
117 or
118 .Xr isspace_l 3 )
119 followed by a single optional
120 .Ql +
121 or
122 .Ql -
123 sign.
124 If
125 .Fa base
126 is zero or 16,
127 the string may then include a
128 .Dq Li 0x
129 prefix,
130 and the number will be read in base 16; otherwise, a zero
131 .Fa base
132 is taken as 10 (decimal) unless the next character is
133 .Ql 0 ,
134 in which case it is taken as 8 (octal).
135 .Pp
136 The remainder of the string is converted to an
137 .Vt "unsigned long"
138 value in the obvious manner,
139 stopping at the end of the string
140 or at the first character that does not produce a valid digit
141 in the given base.
142 (In bases above 10, the letter
143 .Ql A
144 in either upper or lower case
145 represents 10,
146 .Ql B
147 represents 11, and so forth, with
148 .Ql Z
149 representing 35.)
150 .Pp
151 If
152 .Fa endptr
153 is not
154 .Dv NULL ,
155 .Fn strtoul
156 and
157 .Fn strtoul_l
158 store the address of the first invalid character in
159 .Fa *endptr .
160 If there were no digits at all, however,
161 .Fn strtoul
162 and
163 .Fn strtoul_l
164 store the original value of
165 .Fa nptr
166 in
167 .Fa *endptr .
168 (Thus, if
169 .Fa *nptr
170 is not
171 .Ql \e0
172 but
173 .Fa **endptr
174 is
175 .Ql \e0
176 on return, the entire string was valid.)
177 .Pp
178 The
179 .Fn strtoul_l ,
180 .Fn strtoull_l ,
181 and
182 .Fn strtoumax_l
183 functions take an explicit
184 .Fa locale
185 argument, whereas the
186 .Fn strtoul ,
187 .Fn strtoull ,
188 .Fn strtoumax ,
189 and
190 .Fn strtouq
191 functions use the current global or per-thread locale.
192 .Sh RETURN VALUES
193 The
194 .Fn strtoul ,
195 .Fn strtoul_l ,
196 .Fn strtoull ,
197 .Fn strtoull_l ,
198 .Fn strtoumax ,
199 .Fn strtoumax_l ,
200 and
201 .Fn strtouq
202 functions
203 return either the result of the conversion
204 or, if there was a leading minus sign,
205 the negation of the result of the conversion,
206 unless the original (non-negated) value would overflow;
207 in the latter case,
208 .Fn strtoul
209 and
210 .Fn strtoul_l
211 return
212 .Dv ULONG_MAX ,
213 .Fn strtoull
214 and
215 .Fn strtoull_l
216 return
217 .Dv ULLONG_MAX ,
218 .Fn strtoumax
219 and
220 .Fn strtoumax_l
221 return
222 .Dv UINTMAX_MAX ,
223 and
224 .Fn strtouq
225 returns
226 .Dv ULLONG_MAX .
227 In all cases,
228 .Va errno
229 is set to
230 .Er ERANGE .
231 If no conversion could be performed, 0 is returned and
232 the global variable
233 .Va errno
234 is set to
235 .Er EINVAL
236 (the last feature is not portable across all platforms).
237 .Sh ERRORS
238 .Bl -tag -width Er
239 .It Bq Er EINVAL
240 The value of
241 .Fa base
242 is not supported or
243 no conversion could be performed
244 (the last feature is not portable across all platforms).
245 .It Bq Er ERANGE
246 The given string was out of range; the value converted has been clamped.
247 .El
248 .Sh SEE ALSO
249 .Xr strtol 3 ,
250 .Xr strtonum 3 ,
251 .Xr wcstoul 3 ,
252 .Xr xlocale 3
253 .Sh STANDARDS
254 The
255 .Fn strtoul
256 function
257 conforms to
258 .St -isoC .
259 The
260 .Fn strtoull
261 and
262 .Fn strtoumax
263 functions
264 conform to
265 .St -isoC-99 .
266 The
267 .Bx
268 .Fn strtouq
269 function is deprecated.