flag fields are u_int's
[unix-history] / usr / src / lib / libc / stdlib / strtoul.3
CommitLineData
375c4de4
KB
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\"
7.\" %sccs.include.redist.man%
8.\"
9.\" @(#)strtoul.3 5.1 (Berkeley) %G%
10.\"
11.TH STRTOUL 3 ""
12.UC 7
13.SH NAME
14strtoul \- convert a string to an unsigned long integer
15.SH SYNOPSIS
16.B #include <stdlib.h>
17.br
18.B #include <limits.h>
19.PP
20.B "unsigned long strtoul(char *nptr, char **endptr, int base);
21.SH DESCRIPTION
22.B Strtoul
23converts the string in
24.I nptr
25to an
26.B "unsigned long"
27value according to the given
28.IR base ,
29which must be between 2 and 36 inclusive,
30or be the special value 0.
31.PP
32The string may begin with an arbitrary amount of white space
33(as determined by
34.BR isspace ;
35see
36.IR ctype (3)),
37followed by a single optional `+' or `-' sign.
38If
39.I base
40is zero or 16,
41the string may then include a `0x' prefix,
42and the number will be read in base 16; otherwise, a zero
43.I base
44is taken as 10 (decimal) unless the next character is `0',
45in which case it is taken as 8 (octal).
46.PP
47The remainder of the string is converted to an
48.B "unsigned long"
49value in the obvious manner,
50stopping at the end of the string
51or at the first character that does not produce a valid digit
52in the given base.
53(In bases above 10, the letter `A' in either upper or lower case
54represents 10, `B' represents 11, and so forth, with `Z' representing 35.)
55.PP
56If
57.I endptr
58is non nil,
59.B strtoul
60stores the address of the first invalid character in
61.IR *endptr .
62If there were no digits at all, however,
63.B strtoul
64stores the original value of
65.I nptr
66in
67.IR *endptr .
68(Thus, if
69.I *nptr
70is not '\e0' but
71.IR **endptr
72is '\e0' on return, the entire string was valid.)
73.SH RETURN VALUE
74.B Strtoul
75returns either the result of the conversion
76or, if there was a leading minus sign,
77the negation of the result of the conversion,
78unless the original (non-negated) value would overflow;
79in the latter case,
80.B strtoul
81returns
82.B ULONG_MAX
83and sets
84.B errno
85to
86.BR ERANGE .
87.SH ERRORS
88.TP
89[ERANGE]
90The given string was out of range; the value converted has been clamped.
91.SH SEE ALSO
92strtol(3)
93.SH STANDARDS
94.B Strtoul
95conforms to ANSI X3.159-1989 (``ANSI C'').
96.SH BUGS
97Ignores the current locale.