BSD 4_3_Reno release
[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.\"
1c15e888
C
7.\" Redistribution and use in source and binary forms are permitted
8.\" provided that: (1) source distributions retain this entire copyright
9.\" notice and comment, and (2) distributions including binaries display
10.\" the following acknowledgement: ``This product includes software
11.\" developed by the University of California, Berkeley and its contributors''
12.\" in the documentation or other materials provided with the distribution
13.\" and in all advertising materials mentioning features or use of this
14.\" software. Neither the name of the University nor the names of its
15.\" contributors may be used to endorse or promote products derived
16.\" from this software without specific prior written permission.
17.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
375c4de4 20.\"
1c15e888 21.\" @(#)strtoul.3 5.1 (Berkeley) 5/15/90
375c4de4 22.\"
1c15e888 23.TH STRTOUL 3 "May 15, 1990"
375c4de4
KB
24.UC 7
25.SH NAME
26strtoul \- convert a string to an unsigned long integer
27.SH SYNOPSIS
28.B #include <stdlib.h>
29.br
30.B #include <limits.h>
31.PP
32.B "unsigned long strtoul(char *nptr, char **endptr, int base);
33.SH DESCRIPTION
34.B Strtoul
35converts the string in
36.I nptr
37to an
38.B "unsigned long"
39value according to the given
40.IR base ,
41which must be between 2 and 36 inclusive,
42or be the special value 0.
43.PP
44The string may begin with an arbitrary amount of white space
45(as determined by
46.BR isspace ;
47see
48.IR ctype (3)),
49followed by a single optional `+' or `-' sign.
50If
51.I base
52is zero or 16,
53the string may then include a `0x' prefix,
54and the number will be read in base 16; otherwise, a zero
55.I base
56is taken as 10 (decimal) unless the next character is `0',
57in which case it is taken as 8 (octal).
58.PP
59The remainder of the string is converted to an
60.B "unsigned long"
61value in the obvious manner,
62stopping at the end of the string
63or at the first character that does not produce a valid digit
64in the given base.
65(In bases above 10, the letter `A' in either upper or lower case
66represents 10, `B' represents 11, and so forth, with `Z' representing 35.)
67.PP
68If
69.I endptr
70is non nil,
71.B strtoul
72stores the address of the first invalid character in
73.IR *endptr .
74If there were no digits at all, however,
75.B strtoul
76stores the original value of
77.I nptr
78in
79.IR *endptr .
80(Thus, if
81.I *nptr
82is not '\e0' but
83.IR **endptr
84is '\e0' on return, the entire string was valid.)
85.SH RETURN VALUE
86.B Strtoul
87returns either the result of the conversion
88or, if there was a leading minus sign,
89the negation of the result of the conversion,
90unless the original (non-negated) value would overflow;
91in the latter case,
92.B strtoul
93returns
94.B ULONG_MAX
95and sets
96.B errno
97to
98.BR ERANGE .
99.SH ERRORS
100.TP
101[ERANGE]
102The given string was out of range; the value converted has been clamped.
103.SH SEE ALSO
104strtol(3)
105.SH STANDARDS
106.B Strtoul
107conforms to ANSI X3.159-1989 (``ANSI C'').
108.SH BUGS
109Ignores the current locale.