xref: /dragonfly/lib/libc/stdlib/strtoul.3 (revision b40e316c)
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. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed by the University of
19.\"	California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\"    may be used to endorse or promote products derived from this software
22.\"    without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\"     @(#)strtoul.3	8.1 (Berkeley) 6/4/93
37.\" $FreeBSD: src/lib/libc/stdlib/strtoul.3,v 1.3.2.7 2002/01/21 12:30:34 ru Exp $
38.\" $DragonFly: src/lib/libc/stdlib/strtoul.3,v 1.2 2003/06/17 04:26:46 dillon Exp $
39.\"
40.Dd June 4, 1993
41.Dt STRTOUL 3
42.Os
43.Sh NAME
44.Nm strtoul , strtoull , strtouq
45.Nd "convert a string to an"
46.Vt "unsigned long" , "unsigned long long" ,
47or
48.Vt u_quad_t
49integer
50.Sh LIBRARY
51.Lb libc
52.Sh SYNOPSIS
53.In stdlib.h
54.In limits.h
55.Ft "unsigned long"
56.Fn strtoul "const char *nptr" "char **endptr" "int base"
57.Ft "unsigned long long"
58.Fn strtoull "const char *nptr" "char **endptr" "int base"
59.In sys/types.h
60.In stdlib.h
61.In limits.h
62.Ft u_quad_t
63.Fn strtouq "const char *nptr" "char **endptr" "int base"
64.Sh DESCRIPTION
65The
66.Fn strtoul
67function
68converts the string in
69.Fa nptr
70to an
71.Vt "unsigned long"
72value.
73The
74.Fn strtoull
75function
76converts the string in
77.Fa nptr
78to an
79.Vt "unsigned long long"
80value.
81The
82.Fn strtouq
83function
84converts the string in
85.Fa nptr
86to a
87.Vt u_quad_t
88value.
89The conversion is done according to the given
90.Fa base ,
91which must be between 2 and 36 inclusive,
92or be the special value 0.
93.Pp
94The string may begin with an arbitrary amount of white space
95(as determined by
96.Xr isspace 3 )
97followed by a single optional
98.Ql +
99or
100.Ql -
101sign.
102If
103.Fa base
104is zero or 16,
105the string may then include a
106.Dq Li 0x
107prefix,
108and the number will be read in base 16; otherwise, a zero
109.Fa base
110is taken as 10 (decimal) unless the next character is
111.Ql 0 ,
112in which case it is taken as 8 (octal).
113.Pp
114The remainder of the string is converted to an
115.Vt "unsigned long"
116value in the obvious manner,
117stopping at the end of the string
118or at the first character that does not produce a valid digit
119in the given base.
120(In bases above 10, the letter
121.Ql A
122in either upper or lower case
123represents 10,
124.Ql B
125represents 11, and so forth, with
126.Ql Z
127representing 35.)
128.Pp
129If
130.Fa endptr
131is not
132.Dv NULL ,
133.Fn strtoul
134stores the address of the first invalid character in
135.Fa *endptr .
136If there were no digits at all, however,
137.Fn strtoul
138stores the original value of
139.Fa nptr
140in
141.Fa *endptr .
142(Thus, if
143.Fa *nptr
144is not
145.Ql \e0
146but
147.Fa **endptr
148is
149.Ql \e0
150on return, the entire string was valid.)
151.Sh RETURN VALUES
152The
153.Fn strtoul
154function
155returns either the result of the conversion
156or, if there was a leading minus sign,
157the negation of the result of the conversion,
158unless the original (non-negated) value would overflow;
159in the latter case,
160.Fn strtoul
161returns
162.Dv ULONG_MAX .
163The
164.Fn strtoull
165function
166returns either the result of the conversion
167or, if there was a leading minus sign,
168the negation of the result of the conversion,
169unless the original (non-negated) value would overflow;
170in the latter case,
171.Fn strtoull
172returns
173.Dv ULLONG_MAX .
174In all cases,
175.Va errno
176is set to
177.Er ERANGE .
178.Sh ERRORS
179.Bl -tag -width Er
180.It Bq Er ERANGE
181The given string was out of range; the value converted has been clamped.
182.El
183.Sh SEE ALSO
184.Xr strtol 3
185.Sh STANDARDS
186The
187.Fn strtoul
188function
189conforms to
190.St -isoC .
191The
192.Fn strtoull
193function
194conforms to
195.St -isoC-99 .
196The
197.Bx
198.Fn strtouq
199function is deprecated.
200.Sh BUGS
201Ignores the current locale.
202