]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/strtoul.3
sync
[thirdparty/man-pages.git] / man3 / strtoul.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
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.
6.\"
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.
11.\"
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
18.\" professionally.
19.\"
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
22.\"
23.\" References consulted:
24.\" Linux libc source code
25.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26.\" 386BSD man pages
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()
30.\"
31.TH STRTOUL 3 2002-05-30 "GNU" "Linux Programmer's Manual"
32.SH NAME
33strtoul, strtoull, strtouq \- convert a string to an unsigned long integer
34.SH SYNOPSIS
35.nf
36.B #include <stdlib.h>
37.sp
38.BI "unsigned long int"
39.BI "strtoul(const char *" nptr ", char **" endptr ", int " base );
40.sp
41.BI "unsigned long long int"
42.BI "strtoull(const char *" nptr ", char **" endptr ", int " base );
43.fi
44.SH DESCRIPTION
63aa9df0 45The \fBstrtoul\fP() function converts the initial part of the string
fea681da
MK
46in \fInptr\fP to an unsigned long integer value according to the
47given \fIbase\fP, which must be between 2 and 36 inclusive, or be
48the special value 0.
49.PP
3f266a43 50The string may begin with an arbitrary amount of white space (as
fea681da
MK
51determined by
52.BR isspace (3))
8c383102 53followed by a single optional `+' or `\-'
fea681da
MK
54sign. If \fIbase\fP is zero or 16, the string may then include a
55`0x' prefix, and the number will be read in base 16; otherwise, a
56zero \fIbase\fP is taken as 10 (decimal) unless the next character
57is `0', in which case it is taken as 8 (octal).
58.PP
59The remainder of the string is converted to an unsigned long int value
60in the obvious manner, stopping at the first character which is not a
61valid digit in the given base. (In bases above 10, the letter `A' in
62either upper or lower case represents 10, `B' represents 11, and so
63forth, with `Z' representing 35.)
64.PP
63aa9df0 65If \fIendptr\fP is not NULL, \fBstrtoul\fP() stores the address of the
fea681da 66first invalid character in \fI*endptr\fP. If there were no digits at
63aa9df0 67all, \fBstrtoul\fP() stores the original value of \fInptr\fP in
fea681da
MK
68\fI*endptr\fP (and returns 0).
69In particular, if \fI*nptr\fP is not `\\0' but \fI**endptr\fP
70is `\\0' on return, the entire string is valid.
71.PP
72The
63aa9df0 73.BR strtoull ()
fea681da 74function works just like the
63aa9df0 75.BR strtoul ()
fea681da
MK
76function but returns an unsigned long long integer value.
77.SH "RETURN VALUE"
63aa9df0 78The \fBstrtoul\fP() function returns either the result of the conversion
fea681da 79or, if there was a leading minus sign, the negation of the result of the
190c7abe
MK
80conversion represented as an unsigned value,
81unless the original (non-negated) value would overflow; in
63aa9df0 82the latter case, \fBstrtoul\fP() returns ULONG_MAX and sets the global
fea681da
MK
83variable \fIerrno\fP to ERANGE.
84Precisely the same holds for
63aa9df0 85.BR strtoull ()
fea681da
MK
86(with ULLONG_MAX instead of ULONG_MAX).
87.SH ERRORS
88.TP
89.B EINVAL
90(not in C99)
91The given
92.I base
93contains an unsupported value.
94.TP
95.B ERANGE
96The resulting value was out of range.
97.LP
98The implementation may also set \fIerrno\fP to \fBEINVAL\fP in case
99no conversion was performed (no digits seen, and 0 returned).
100.SH NOTES
fefe023e
MK
101Since
102.BR strtoul ()
8699b7dd 103can legitimately return 0 or LONG_MAX (LLONG_MAX for
fefe023e
MK
104.BR strtoull ())
105on both success and failure, the calling program should set
106.I errno
107to 0 before the call,
108and then determine if an error occurred by checking whether
109.I errno
110has a non-zero value after the call.
111
190c7abe 112In locales other than the "C" locale, other strings may be accepted.
fea681da
MK
113(For example, the thousands separator of the current locale may be
114supported.)
115.LP
116BSD also has
117.sp
118.in +4n
119.nf
120.BI "u_quad_t"
121.BI "strtouq(const char *" nptr ", char **" endptr ", int base" );
122.sp
123.in -4n
124.fi
125with completely analogous definition.
126Depending on the wordsize of the current architecture, this
127may be equivalent to
63aa9df0 128.BR strtoull ()
fea681da 129or to
63aa9df0 130.BR strtoul ().
190c7abe
MK
131
132Negative values are considered valid input and are
133silently converted to the equivalent unsigned long value.
fea681da 134.SH "CONFORMING TO"
63aa9df0 135.BR strtoul ()
1eb85d14 136conforms to SVr4, C89, C99 and POSIX-2001, and
63aa9df0 137.BR strtoull ()
68e1685c 138to C99 and POSIX.1-2001.
5a1cae6b
MK
139.SH EXAMPLE
140See the example on the
141.BR strtol (3)
142manual page;
143the use of the functions described in this manual page is similar.
fea681da
MK
144.SH "SEE ALSO"
145.BR atof (3),
146.BR atoi (3),
147.BR atol (3),
148.BR strtod (3),
149.BR strtol (3)