1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" Modified Sun Jul 25 10:54:03 1993 by Rik Faith (faith@cs.unc.edu)
10 .\" Fixed typo, aeb, 950823
11 .\" 2002-02-22, joey, mihtjel: Added strtoull()
13 .TH STRTOUL 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
15 strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
18 .RI ( libc ", " \-lc )
21 .B #include <stdlib.h>
23 .BI "unsigned long strtoul(const char *restrict " nptr ,
24 .BI " char **restrict " endptr ", int " base );
25 .BI "unsigned long long strtoull(const char *restrict " nptr ,
26 .BI " char **restrict " endptr ", int " base );
30 Feature Test Macro Requirements for glibc (see
31 .BR feature_test_macros (7)):
37 || /* Glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
42 function converts the initial part of the string
47 value according to the
50 which must be between 2 and 36 inclusive, or be
53 The string may begin with an arbitrary amount of white space (as
56 followed by a single optional \(aq+\(aq or \(aq\-\(aq
60 is zero or 16, the string may then include a
61 "0x" prefix, and the number will be read in base 16; otherwise, a
64 is taken as 10 (decimal) unless the next character
65 is \(aq0\(aq, in which case it is taken as 8 (octal).
67 The remainder of the string is converted to an
69 value in the obvious manner,
70 stopping at the first character which is not a
71 valid digit in the given base.
72 (In bases above 10, the letter \(aqA\(aq in
73 either uppercase or lowercase represents 10, \(aqB\(aq represents 11, and so
74 forth, with \(aqZ\(aq representing 35.)
80 stores the address of the
81 first invalid character in
83 If there were no digits at
86 stores the original value of
93 is not \(aq\e0\(aq but
95 is \(aq\e0\(aq on return, the entire string is valid.
99 function works just like the
101 function but returns an
102 .I "unsigned long long"
107 function returns either the result of the conversion
108 or, if there was a leading minus sign, the negation of the result of the
109 conversion represented as an unsigned value,
110 unless the original (nonnegated) value would overflow; in
119 Precisely the same holds for
131 contains an unsupported value.
134 The resulting value was out of range.
136 The implementation may also set
141 no conversion was performed (no digits seen, and 0 returned).
143 For an explanation of the terms used in this section, see
151 Interface Attribute Value
156 T} Thread safety MT-Safe locale
163 POSIX.1-2001, POSIX.1-2008, C89, C99 SVr4.
166 POSIX.1-2001, POSIX.1-2008, C99.
170 can legitimately return 0 or
175 on both success and failure, the calling program should set
177 to 0 before the call,
178 and then determine if an error occurred by checking whether
180 has a nonzero value after the call.
182 In locales other than the "C" locale, other strings may be accepted.
183 (For example, the thousands separator of the current locale may be
190 .BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base );
194 with completely analogous definition.
195 Depending on the wordsize of the current architecture, this
201 Negative values are considered valid input and are
202 silently converted to the equivalent
206 See the example on the
209 the use of the functions described in this manual page is similar.