Only one name per .Nm macro for better readability.
[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. 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.3 2005/08/05 22:35:10 swildner Exp $
39 .\"
40 .Dd June 4, 1993
41 .Dt STRTOUL 3
42 .Os
43 .Sh NAME
44 .Nm strtoul ,
45 .Nm strtoull ,
46 .Nm strtouq
47 .Nd "convert a string to an"
48 .Vt "unsigned long" , "unsigned long long" ,
49 or
50 .Vt u_quad_t
51 integer
52 .Sh LIBRARY
53 .Lb libc
54 .Sh SYNOPSIS
55 .In stdlib.h
56 .In limits.h
57 .Ft "unsigned long"
58 .Fn strtoul "const char *nptr" "char **endptr" "int base"
59 .Ft "unsigned long long"
60 .Fn strtoull "const char *nptr" "char **endptr" "int base"
61 .In sys/types.h
62 .In stdlib.h
63 .In limits.h
64 .Ft u_quad_t
65 .Fn strtouq "const char *nptr" "char **endptr" "int base"
66 .Sh DESCRIPTION
67 The
68 .Fn strtoul
69 function
70 converts the string in
71 .Fa nptr
72 to an
73 .Vt "unsigned long"
74 value.
75 The
76 .Fn strtoull
77 function
78 converts the string in
79 .Fa nptr
80 to an
81 .Vt "unsigned long long"
82 value.
83 The
84 .Fn strtouq
85 function
86 converts the string in
87 .Fa nptr
88 to a
89 .Vt u_quad_t
90 value.
91 The conversion is done according to the given
92 .Fa base ,
93 which must be between 2 and 36 inclusive,
94 or be the special value 0.
95 .Pp
96 The string may begin with an arbitrary amount of white space
97 (as determined by
98 .Xr isspace 3 )
99 followed by a single optional
100 .Ql +
101 or
102 .Ql -
103 sign.
104 If
105 .Fa base
106 is zero or 16,
107 the string may then include a
108 .Dq Li 0x
109 prefix,
110 and the number will be read in base 16; otherwise, a zero
111 .Fa base
112 is taken as 10 (decimal) unless the next character is
113 .Ql 0 ,
114 in which case it is taken as 8 (octal).
115 .Pp
116 The remainder of the string is converted to an
117 .Vt "unsigned long"
118 value in the obvious manner,
119 stopping at the end of the string
120 or at the first character that does not produce a valid digit
121 in the given base.
122 (In bases above 10, the letter
123 .Ql A
124 in either upper or lower case
125 represents 10,
126 .Ql B
127 represents 11, and so forth, with
128 .Ql Z
129 representing 35.)
130 .Pp
131 If
132 .Fa endptr
133 is not
134 .Dv NULL ,
135 .Fn strtoul
136 stores the address of the first invalid character in
137 .Fa *endptr .
138 If there were no digits at all, however,
139 .Fn strtoul
140 stores the original value of
141 .Fa nptr
142 in
143 .Fa *endptr .
144 (Thus, if
145 .Fa *nptr
146 is not
147 .Ql \e0
148 but
149 .Fa **endptr
150 is
151 .Ql \e0
152 on return, the entire string was valid.)
153 .Sh RETURN VALUES
154 The
155 .Fn strtoul
156 function
157 returns either the result of the conversion
158 or, if there was a leading minus sign,
159 the negation of the result of the conversion,
160 unless the original (non-negated) value would overflow;
161 in the latter case,
162 .Fn strtoul
163 returns
164 .Dv ULONG_MAX .
165 The
166 .Fn strtoull
167 function
168 returns either the result of the conversion
169 or, if there was a leading minus sign,
170 the negation of the result of the conversion,
171 unless the original (non-negated) value would overflow;
172 in the latter case,
173 .Fn strtoull
174 returns
175 .Dv ULLONG_MAX .
176 In all cases,
177 .Va errno
178 is set to
179 .Er ERANGE .
180 .Sh ERRORS
181 .Bl -tag -width Er
182 .It Bq Er ERANGE
183 The given string was out of range; the value converted has been clamped.
184 .El
185 .Sh SEE ALSO
186 .Xr strtol 3
187 .Sh STANDARDS
188 The
189 .Fn strtoul
190 function
191 conforms to
192 .St -isoC .
193 The
194 .Fn strtoull
195 function
196 conforms to
197 .St -isoC-99 .
198 The
199 .Bx
200 .Fn strtouq
201 function is deprecated.
202 .Sh BUGS
203 Ignores the current locale.