1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified Sun Jul 25 10:54:03 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Fixed typo, aeb, 950823
29 .\" 2002-02-22, joey, mihtjel: Added strtoull()
31 .TH STRTOUL 3 2002-05-30 "GNU" "Linux Programmer's Manual"
33 strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
36 .B #include <stdlib.h>
38 .BI "unsigned long int"
39 .BI "strtoul(const char *" nptr ", char **" endptr ", int " base );
41 .BI "unsigned long long int"
42 .BI "strtoull(const char *" nptr ", char **" endptr ", int " base );
47 function converts the initial part of the string
48 in \fInptr\fP to an unsigned long integer value according to the
49 given \fIbase\fP, which must be between 2 and 36 inclusive, or be
52 The string may begin with an arbitrary amount of white space (as
55 followed by a single optional `+' or `\-'
57 If \fIbase\fP is zero or 16, the string may then include a
58 `0x' prefix, and the number will be read in base 16; otherwise, a
59 zero \fIbase\fP is taken as 10 (decimal) unless the next character
60 is `0', in which case it is taken as 8 (octal).
62 The remainder of the string is converted to an unsigned long int value
63 in the obvious manner, stopping at the first character which is not a
64 valid digit in the given base.
65 (In bases above 10, the letter `A' in
66 either upper or lower case represents 10, `B' represents 11, and so
67 forth, with `Z' representing 35.)
69 If \fIendptr\fP is not NULL,
71 stores the address of the
72 first invalid character in \fI*endptr\fP.
73 If there were no digits at
76 stores the original value of \fInptr\fP in
77 \fI*endptr\fP (and returns 0).
78 In particular, if \fI*nptr\fP is not `\\0' but \fI**endptr\fP
79 is `\\0' on return, the entire string is valid.
83 function works just like the
85 function but returns an unsigned long long integer value.
89 function returns either the result of the conversion
90 or, if there was a leading minus sign, the negation of the result of the
91 conversion represented as an unsigned value,
92 unless the original (non-negated) value would overflow; in
95 returns ULONG_MAX and sets the global
96 variable \fIerrno\fP to ERANGE.
97 Precisely the same holds for
99 (with ULLONG_MAX instead of ULONG_MAX).
106 contains an unsupported value.
109 The resulting value was out of range.
111 The implementation may also set \fIerrno\fP to \fBEINVAL\fP in case
112 no conversion was performed (no digits seen, and 0 returned).
115 conforms to SVr4, C89, C99 and POSIX-2001, and
117 to C99 and POSIX.1-2001.
121 can legitimately return 0 or LONG_MAX (LLONG_MAX for
123 on both success and failure, the calling program should set
125 to 0 before the call,
126 and then determine if an error occurred by checking whether
128 has a non-zero value after the call.
130 In locales other than the "C" locale, other strings may be accepted.
131 (For example, the thousands separator of the current locale may be
139 .BI "strtouq(const char *" nptr ", char **" endptr ", int base" );
143 with completely analogous definition.
144 Depending on the wordsize of the current architecture, this
150 Negative values are considered valid input and are
151 silently converted to the equivalent unsigned long value.
153 See the example on the
156 the use of the functions described in this manual page is similar.