]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strtoul.3
tcp.7: Update info on tcp_syn_retries default value
[thirdparty/man-pages.git] / man3 / strtoul.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\" 386BSD man pages
29 .\" Modified Sun Jul 25 10:54:03 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Fixed typo, aeb, 950823
31 .\" 2002-02-22, joey, mihtjel: Added strtoull()
32 .\"
33 .TH STRTOUL 3 2019-03-06 "GNU" "Linux Programmer's Manual"
34 .SH NAME
35 strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
36 .SH SYNOPSIS
37 .nf
38 .B #include <stdlib.h>
39 .PP
40 .BI "unsigned long int strtoul(const char *" nptr ", char **" endptr \
41 ", int " base );
42 .PP
43 .BI "unsigned long long int strtoull(const char *" nptr ", char **" endptr ,
44 .BI " int " base );
45 .fi
46 .PP
47 .in -4n
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
50 .in
51 .PP
52 .ad l
53 .BR strtoull ():
54 .RS 4
55 _ISOC99_SOURCE ||
56 || /* Glibc versions <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
57 .RE
58 .ad
59 .SH DESCRIPTION
60 The
61 .BR strtoul ()
62 function converts the initial part of the string
63 in
64 .I nptr
65 to an
66 .I "unsigned long int"
67 value according to the
68 given
69 .IR base ,
70 which must be between 2 and 36 inclusive, or be
71 the special value 0.
72 .PP
73 The string may begin with an arbitrary amount of white space (as
74 determined by
75 .BR isspace (3))
76 followed by a single optional \(aq+\(aq or \(aq\-\(aq
77 sign.
78 If
79 .I base
80 is zero or 16, the string may then include a
81 "0x" prefix, and the number will be read in base 16; otherwise, a
82 zero
83 .I base
84 is taken as 10 (decimal) unless the next character
85 is \(aq0\(aq, in which case it is taken as 8 (octal).
86 .PP
87 The remainder of the string is converted to an
88 .I "unsigned long int"
89 value in the obvious manner,
90 stopping at the first character which is not a
91 valid digit in the given base.
92 (In bases above 10, the letter \(aqA\(aq in
93 either uppercase or lowercase represents 10, \(aqB\(aq represents 11, and so
94 forth, with \(aqZ\(aq representing 35.)
95 .PP
96 If
97 .I endptr
98 is not NULL,
99 .BR strtoul ()
100 stores the address of the
101 first invalid character in
102 .IR *endptr .
103 If there were no digits at
104 all,
105 .BR strtoul ()
106 stores the original value of
107 .I nptr
108 in
109 .I *endptr
110 (and returns 0).
111 In particular, if
112 .I *nptr
113 is not \(aq\e0\(aq but
114 .I **endptr
115 is \(aq\e0\(aq on return, the entire string is valid.
116 .PP
117 The
118 .BR strtoull ()
119 function works just like the
120 .BR strtoul ()
121 function but returns an
122 .I "unsigned long long int"
123 value.
124 .SH RETURN VALUE
125 The
126 .BR strtoul ()
127 function returns either the result of the conversion
128 or, if there was a leading minus sign, the negation of the result of the
129 conversion represented as an unsigned value,
130 unless the original (nonnegated) value would overflow; in
131 the latter case,
132 .BR strtoul ()
133 returns
134 .B ULONG_MAX
135 and sets
136 .I errno
137 to
138 .BR ERANGE .
139 Precisely the same holds for
140 .BR strtoull ()
141 (with
142 .B ULLONG_MAX
143 instead of
144 .BR ULONG_MAX ).
145 .SH ERRORS
146 .TP
147 .B EINVAL
148 (not in C99)
149 The given
150 .I base
151 contains an unsupported value.
152 .TP
153 .B ERANGE
154 The resulting value was out of range.
155 .PP
156 The implementation may also set
157 .IR errno
158 to
159 .B EINVAL
160 in case
161 no conversion was performed (no digits seen, and 0 returned).
162 .SH ATTRIBUTES
163 For an explanation of the terms used in this section, see
164 .BR attributes (7).
165 .TS
166 allbox;
167 lbw32 lb lb
168 l l l.
169 Interface Attribute Value
170 T{
171 .BR strtoul (),
172 .BR strtoull (),
173 .BR strtouq ()
174 T} Thread safety MT-Safe locale
175 .TE
176 .SH CONFORMING TO
177 .BR strtoul ():
178 POSIX.1-2001, POSIX.1-2008, C89, C99 SVr4.
179 .PP
180 .BR strtoull ():
181 POSIX.1-2001, POSIX.1-2008, C99.
182 .SH NOTES
183 Since
184 .BR strtoul ()
185 can legitimately return 0 or
186 .B ULONG_MAX
187 .RB ( ULLONG_MAX
188 for
189 .BR strtoull ())
190 on both success and failure, the calling program should set
191 .I errno
192 to 0 before the call,
193 and then determine if an error occurred by checking whether
194 .I errno
195 has a nonzero value after the call.
196 .PP
197 In locales other than the "C" locale, other strings may be accepted.
198 (For example, the thousands separator of the current locale may be
199 supported.)
200 .PP
201 BSD also has
202 .PP
203 .in +4n
204 .EX
205 .BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base );
206 .EE
207 .in
208 .PP
209 with completely analogous definition.
210 Depending on the wordsize of the current architecture, this
211 may be equivalent to
212 .BR strtoull ()
213 or to
214 .BR strtoul ().
215 .PP
216 Negative values are considered valid input and are
217 silently converted to the equivalent
218 .I "unsigned long int"
219 value.
220 .SH EXAMPLE
221 See the example on the
222 .BR strtol (3)
223 manual page;
224 the use of the functions described in this manual page is similar.
225 .SH SEE ALSO
226 .BR a64l (3),
227 .BR atof (3),
228 .BR atoi (3),
229 .BR atol (3),
230 .BR strtod (3),
231 .BR strtol (3),
232 .BR strtoumax (3)