]> git.saurik.com Git - apple/libc.git/blame_incremental - stdlib/FreeBSD/strtoul.3
Libc-825.24.tar.gz
[apple/libc.git] / stdlib / FreeBSD / strtoul.3
... / ...
CommitLineData
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.\" 4. 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 November 28, 2001
36.Dt STRTOUL 3
37.Os
38.Sh NAME
39.Nm strtoul ,
40.Nm strtoull ,
41.Nm strtoumax ,
42.Nm strtouq
43.Nd "convert a string to an"
44.Vt "unsigned long" , "unsigned long long" , uintmax_t ,
45or
46.Vt u_quad_t
47integer
48.Sh LIBRARY
49.Lb libc
50.Sh SYNOPSIS
51.In stdlib.h
52.Ft "unsigned long"
53.Fo strtoul
54.Fa "const char *restrict str"
55.Fa "char **restrict endptr"
56.Fa "int base"
57.Fc
58.Ft "unsigned long long"
59.Fo strtoull
60.Fa "const char *restrict str"
61.Fa "char **restrict endptr"
62.Fa "int base"
63.Fc
64.In inttypes.h
65.Ft uintmax_t
66.Fo strtoumax
67.Fa "const char *restrict str"
68.Fa "char **restrict endptr"
69.Fa "int base"
70.Fc
71.In sys/types.h
72.In stdlib.h
73.In limits.h
74.Ft u_quad_t
75.Fo strtouq
76.Fa "const char *str"
77.Fa "char **endptr"
78.Fa "int base"
79.Fc
80.Sh DESCRIPTION
81The
82.Fn strtoul
83function
84converts the string in
85.Fa str
86to an
87.Vt "unsigned long"
88value.
89The
90.Fn strtoull
91function
92converts the string in
93.Fa str
94to an
95.Vt "unsigned long long"
96value.
97The
98.Fn strtoumax
99function
100converts the string in
101.Fa str
102to an
103.Vt uintmax_t
104value.
105The
106.Fn strtouq
107function
108converts the string in
109.Fa str
110to a
111.Vt u_quad_t
112value.
113The conversion is done according to the given
114.Fa base ,
115which must be between 2 and 36 inclusive,
116or be the special value 0.
117.Pp
118The string may begin with an arbitrary amount of white space
119(as determined by
120.Xr isspace 3 )
121followed by a single optional
122.Ql +
123or
124.Ql -
125sign.
126If
127.Fa base
128is zero or 16,
129the string may then include a
130.Dq Li 0x
131prefix,
132and the number will be read in base 16; otherwise, a zero
133.Fa base
134is taken as 10 (decimal) unless the next character is
135.Ql 0 ,
136in which case it is taken as 8 (octal).
137.Pp
138The remainder of the string is converted to an
139.Vt "unsigned long"
140value in the obvious manner,
141stopping at the end of the string
142or at the first character that does not produce a valid digit
143in the given base.
144(In bases above 10, the letter
145.Ql A
146in either upper or lower case
147represents 10,
148.Ql B
149represents 11, and so forth, with
150.Ql Z
151representing 35.)
152.Pp
153If
154.Fa endptr
155is not
156.Dv NULL ,
157.Fn strtoul
158stores the address of the first invalid character in
159.Fa *endptr .
160If there were no digits at all, however,
161.Fn strtoul
162stores the original value of
163.Fa str
164in
165.Fa *endptr .
166(Thus, if
167.Fa *str
168is not
169.Ql \e0
170but
171.Fa **endptr
172is
173.Ql \e0
174on return, the entire string was valid.)
175.Sh RETURN VALUES
176The
177.Fn strtoul ,
178.Fn strtoull ,
179.Fn strtoumax
180and
181.Fn strtouq
182functions
183return either the result of the conversion
184or, if there was a leading minus sign,
185the negation of the result of the conversion,
186unless the original (non-negated) value would overflow;
187in the latter case,
188.Fn strtoul
189returns
190.Dv ULONG_MAX ,
191.Fn strtoull
192returns
193.Dv ULLONG_MAX ,
194.Fn strtoumax
195returns
196.Dv UINTMAX_MAX ,
197and
198.Fn strtouq
199returns
200.Dv ULLONG_MAX .
201In all cases,
202.Va errno
203is set to
204.Er ERANGE .
205If no conversion could be performed, 0 is returned and
206the global variable
207.Va errno
208is set to
209.Er EINVAL
210(the last feature is not portable across all platforms).
211.Sh ERRORS
212.Bl -tag -width Er
213.It Bq Er EINVAL
214The value of
215.Fa base
216is not supported or
217no conversion could be performed
218(the last feature is not portable across all platforms).
219.It Bq Er ERANGE
220The given string was out of range; the value converted has been clamped.
221.El
222.Sh LEGACY SYNOPSIS
223.Fd #include <stdlib.h>
224.Fd #include <limits.h>
225.Pp
226.In limits.h
227is necessary for the
228.Fn strtoul
229and
230.Fn strtoull
231functions.
232.Sh SEE ALSO
233.Xr strtol 3 ,
234.Xr strtol_l 3 ,
235.Xr strtonum 3 ,
236.Xr wcstoul 3 ,
237.Xr compat 5
238.Sh STANDARDS
239The
240.Fn strtoul
241function
242conforms to
243.St -isoC .
244The
245.Fn strtoull
246and
247.Fn strtoumax
248functions
249conform to
250.St -isoC-99 .
251The
252.Bx
253.Fn strtouq
254function is deprecated.