1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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()
33 .TH STRTOUL 3 2011-09-15 "GNU" "Linux Programmer's Manual"
35 strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
38 .B #include <stdlib.h>
40 .BI "unsigned long int strtoul(const char *" nptr ", char **" endptr \
43 .BI "unsigned long long int strtoull(const char *" nptr ", char **" endptr ,
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
55 XOPEN_SOURCE\ >=\ 600 || _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE ||
56 _POSIX_C_SOURCE\ >=\ 200112L;
65 function converts the initial part of the string
69 .I "unsigned long int"
70 value according to the
73 which must be between 2 and 36 inclusive, or be
76 The string may begin with an arbitrary amount of white space (as
79 followed by a single optional \(aq+\(aq or \(aq\-\(aq
83 is zero or 16, the string may then include a
84 "0x" prefix, and the number will be read in base 16; otherwise, a
87 is taken as 10 (decimal) unless the next character
88 is \(aq0\(aq, in which case it is taken as 8 (octal).
90 The remainder of the string is converted to an
91 .I "unsigned long int"
92 value in the obvious manner,
93 stopping at the first character which is not a
94 valid digit in the given base.
95 (In bases above 10, the letter \(aqA\(aq in
96 either upper or lower case represents 10, \(aqB\(aq represents 11, and so
97 forth, with \(aqZ\(aq representing 35.)
103 stores the address of the
104 first invalid character in
106 If there were no digits at
109 stores the original value of
116 is not \(aq\\0\(aq but
118 is \(aq\\0\(aq on return, the entire string is valid.
122 function works just like the
124 function but returns an
125 .I "unsigned long long int"
130 function returns either the result of the conversion
131 or, if there was a leading minus sign, the negation of the result of the
132 conversion represented as an unsigned value,
133 unless the original (nonnegated) value would overflow; in
142 Precisely the same holds for
154 contains an unsupported value.
157 The resulting value was out of range.
159 The implementation may also set
164 no conversion was performed (no digits seen, and 0 returned).
167 conforms to SVr4, C89, C99 and POSIX-2001, and
169 to C99 and POSIX.1-2001.
173 can legitimately return 0 or
178 on both success and failure, the calling program should set
180 to 0 before the call,
181 and then determine if an error occurred by checking whether
183 has a nonzero value after the call.
185 In locales other than the "C" locale, other strings may be accepted.
186 (For example, the thousands separator of the current locale may be
193 .BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base );
197 with completely analogous definition.
198 Depending on the wordsize of the current architecture, this
204 Negative values are considered valid input and are
205 silently converted to the equivalent
206 .I "unsigned long int"
209 See the example on the
212 the use of the functions described in this manual page is similar.