]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strtoul.3
Removed trailing white space at end of lines
[thirdparty/man-pages.git] / man3 / strtoul.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
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.\"
f81c6cc6 33.TH STRTOUL 3 2011-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
34.SH NAME
35strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
36.SH SYNOPSIS
37.nf
38.B #include <stdlib.h>
39.sp
62218dc0
MK
40.BI "unsigned long int strtoul(const char *" nptr ", char **" endptr \
41", int " base );
fea681da 42.sp
62218dc0
MK
43.BI "unsigned long long int strtoull(const char *" nptr ", char **" endptr ,
44.BI " int " base );
fea681da 45.fi
cc4615cc
MK
46.sp
47.in -4n
48Feature Test Macro Requirements for glibc (see
49.BR feature_test_macros (7)):
50.in
51.sp
52.ad l
53.BR strtoull ():
e0a98111 54.RS 4
98dbe7af 55XOPEN_SOURCE\ >=\ 600 || _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE ||
6c3f0228 56_POSIX_C_SOURCE\ >=\ 200112L;
e0a98111
MK
57.br
58or
cc4615cc 59.I cc\ -std=c99
e0a98111
MK
60.RE
61.ad
fea681da 62.SH DESCRIPTION
60a90ecd
MK
63The
64.BR strtoul ()
65function converts the initial part of the string
46d8df8e
MK
66in
67.I nptr
68to an
d9a10d9d
MK
69.I "unsigned long int"
70value according to the
46d8df8e
MK
71given
72.IR base ,
73which must be between 2 and 36 inclusive, or be
fea681da
MK
74the special value 0.
75.PP
3f266a43 76The string may begin with an arbitrary amount of white space (as
fea681da
MK
77determined by
78.BR isspace (3))
f81fb444 79followed by a single optional \(aq+\(aq or \(aq\-\(aq
c13182ef 80sign.
46d8df8e
MK
81If
82.I base
83is zero or 16, the string may then include a
928410b4 84"0x" prefix, and the number will be read in base 16; otherwise, a
46d8df8e
MK
85zero
86.I base
87is taken as 10 (decimal) unless the next character
f81fb444 88is \(aq0\(aq, in which case it is taken as 8 (octal).
fea681da 89.PP
d9a10d9d
MK
90The remainder of the string is converted to an
91.I "unsigned long int"
92value in the obvious manner,
93stopping at the first character which is not a
c13182ef 94valid digit in the given base.
f81fb444
MK
95(In bases above 10, the letter \(aqA\(aq in
96either upper or lower case represents 10, \(aqB\(aq represents 11, and so
97forth, with \(aqZ\(aq representing 35.)
fea681da 98.PP
46d8df8e
MK
99If
100.I endptr
101is not NULL,
60a90ecd
MK
102.BR strtoul ()
103stores the address of the
46d8df8e
MK
104first invalid character in
105.IR *endptr .
c13182ef 106If there were no digits at
60a90ecd
MK
107all,
108.BR strtoul ()
46d8df8e
MK
109stores the original value of
110.I nptr
111in
112.I *endptr
113(and returns 0).
114In particular, if
115.I *nptr
116is not \(aq\\0\(aq but
117.I **endptr
f81fb444 118is \(aq\\0\(aq on return, the entire string is valid.
fea681da
MK
119.PP
120The
63aa9df0 121.BR strtoull ()
fea681da 122function works just like the
63aa9df0 123.BR strtoul ()
d9a10d9d
MK
124function but returns an
125.I "unsigned long long int"
126value.
47297adb 127.SH RETURN VALUE
60a90ecd
MK
128The
129.BR strtoul ()
130function returns either the result of the conversion
fea681da 131or, if there was a leading minus sign, the negation of the result of the
c13182ef 132conversion represented as an unsigned value,
74cee559 133unless the original (nonnegated) value would overflow; in
60a90ecd
MK
134the latter case,
135.BR strtoul ()
a9b4ebbc
MK
136returns
137.B ULONG_MAX
46d8df8e
MK
138and sets
139.I errno
140to
a9b4ebbc 141.BR ERANGE .
fea681da 142Precisely the same holds for
63aa9df0 143.BR strtoull ()
a9b4ebbc
MK
144(with
145.B ULLONG_MAX
146instead of
147.BR ULONG_MAX ).
fea681da
MK
148.SH ERRORS
149.TP
150.B EINVAL
151(not in C99)
152The given
153.I base
154contains an unsupported value.
155.TP
156.B ERANGE
157The resulting value was out of range.
158.LP
46d8df8e 159The implementation may also set
51700fd7 160.IR errno
46d8df8e
MK
161to
162.B EINVAL
163in case
fea681da 164no conversion was performed (no digits seen, and 0 returned).
47297adb 165.SH CONFORMING TO
2b2581ee
MK
166.BR strtoul ()
167conforms to SVr4, C89, C99 and POSIX-2001, and
168.BR strtoull ()
169to C99 and POSIX.1-2001.
fea681da 170.SH NOTES
c13182ef 171Since
fefe023e 172.BR strtoul ()
a9b4ebbc 173can legitimately return 0 or
9c60f8f4
MK
174.B ULONG_MAX
175.RB ( ULLONG_MAX
a9b4ebbc 176for
fefe023e
MK
177.BR strtoull ())
178on both success and failure, the calling program should set
179.I errno
c13182ef 180to 0 before the call,
fefe023e
MK
181and then determine if an error occurred by checking whether
182.I errno
c7094399 183has a nonzero value after the call.
fefe023e 184
190c7abe 185In locales other than the "C" locale, other strings may be accepted.
fea681da
MK
186(For example, the thousands separator of the current locale may be
187supported.)
188.LP
189BSD also has
190.sp
191.in +4n
192.nf
37370164 193.BI "u_quad_t strtouq(const char *" nptr ", char **" endptr ", int " base );
fea681da
MK
194.sp
195.in -4n
196.fi
197with completely analogous definition.
198Depending on the wordsize of the current architecture, this
199may be equivalent to
63aa9df0 200.BR strtoull ()
fea681da 201or to
63aa9df0 202.BR strtoul ().
190c7abe
MK
203
204Negative values are considered valid input and are
d9a10d9d
MK
205silently converted to the equivalent
206.I "unsigned long int"
207value.
5a1cae6b
MK
208.SH EXAMPLE
209See the example on the
210.BR strtol (3)
c13182ef 211manual page;
5a1cae6b 212the use of the functions described in this manual page is similar.
47297adb 213.SH SEE ALSO
fea681da
MK
214.BR atof (3),
215.BR atoi (3),
216.BR atol (3),
217.BR strtod (3),
218.BR strtol (3)