Commit | Line | Data |
---|---|---|
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 | |
14 | strtoul \- 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 | |
23 | converts the string in | |
24 | .I nptr | |
25 | to an | |
26 | .B "unsigned long" | |
27 | value according to the given | |
28 | .IR base , | |
29 | which must be between 2 and 36 inclusive, | |
30 | or be the special value 0. | |
31 | .PP | |
32 | The string may begin with an arbitrary amount of white space | |
33 | (as determined by | |
34 | .BR isspace ; | |
35 | see | |
36 | .IR ctype (3)), | |
37 | followed by a single optional `+' or `-' sign. | |
38 | If | |
39 | .I base | |
40 | is zero or 16, | |
41 | the string may then include a `0x' prefix, | |
42 | and the number will be read in base 16; otherwise, a zero | |
43 | .I base | |
44 | is taken as 10 (decimal) unless the next character is `0', | |
45 | in which case it is taken as 8 (octal). | |
46 | .PP | |
47 | The remainder of the string is converted to an | |
48 | .B "unsigned long" | |
49 | value in the obvious manner, | |
50 | stopping at the end of the string | |
51 | or at the first character that does not produce a valid digit | |
52 | in the given base. | |
53 | (In bases above 10, the letter `A' in either upper or lower case | |
54 | represents 10, `B' represents 11, and so forth, with `Z' representing 35.) | |
55 | .PP | |
56 | If | |
57 | .I endptr | |
58 | is non nil, | |
59 | .B strtoul | |
60 | stores the address of the first invalid character in | |
61 | .IR *endptr . | |
62 | If there were no digits at all, however, | |
63 | .B strtoul | |
64 | stores the original value of | |
65 | .I nptr | |
66 | in | |
67 | .IR *endptr . | |
68 | (Thus, if | |
69 | .I *nptr | |
70 | is not '\e0' but | |
71 | .IR **endptr | |
72 | is '\e0' on return, the entire string was valid.) | |
73 | .SH RETURN VALUE | |
74 | .B Strtoul | |
75 | returns either the result of the conversion | |
76 | or, if there was a leading minus sign, | |
77 | the negation of the result of the conversion, | |
78 | unless the original (non-negated) value would overflow; | |
79 | in the latter case, | |
80 | .B strtoul | |
81 | returns | |
82 | .B ULONG_MAX | |
83 | and sets | |
84 | .B errno | |
85 | to | |
86 | .BR ERANGE . | |
87 | .SH ERRORS | |
88 | .TP | |
89 | [ERANGE] | |
90 | The given string was out of range; the value converted has been clamped. | |
91 | .SH SEE ALSO | |
92 | strtol(3) | |
93 | .SH STANDARDS | |
94 | .B Strtoul | |
95 | conforms to ANSI X3.159-1989 (``ANSI C''). | |
96 | .SH BUGS | |
97 | Ignores the current locale. |