Commit | Line | Data |
---|---|---|
fa98d382 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 | .\" @(#)strtol.3 5.1 (Berkeley) %G% | |
10 | .\" | |
11 | .TH STRTOL 3 "" | |
12 | .UC 7 | |
13 | .SH NAME | |
14 | strtol \- convert a string to a long integer | |
15 | .SH SYNOPSIS | |
16 | .B #include <stdlib.h> | |
17 | .br | |
18 | .B #include <limits.h> | |
19 | .PP | |
20 | .B "long strtol(char *nptr, char **endptr, int base); | |
21 | .SH DESCRIPTION | |
22 | .B Strtol | |
23 | converts the string in | |
24 | .I nptr | |
25 | to a | |
26 | .B 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 a | |
48 | .B long | |
49 | value in the obvious manner, | |
50 | stopping at the first character which is not a valid digit | |
51 | in the given base. | |
52 | (In bases above 10, the letter `A' in either upper or lower case | |
53 | represents 10, `B' represents 11, and so forth, with `Z' representing 35.) | |
54 | .PP | |
55 | If | |
56 | .I endptr | |
57 | is non nil, | |
58 | .B strtol | |
59 | stores the address of the first invalid character in | |
60 | .IR *endptr . | |
61 | If there were no digits at all, however, | |
62 | .B strtol | |
63 | stores the original value of | |
64 | .I nptr | |
65 | in | |
66 | .IR *endptr . | |
67 | (Thus, if | |
68 | .I *nptr | |
69 | is not '\e0' but | |
70 | .IR **endptr | |
71 | is '\e0' on return, the entire string was valid.) | |
72 | .SH RETURN VALUE | |
73 | .B Strtol | |
74 | returns the result of the conversion, | |
75 | unless the value would underflow or overflow. | |
76 | If an underflow occurs, | |
77 | .B strtol | |
78 | returns | |
79 | .BR LONG_MIN . | |
80 | If an overflow occurs, | |
81 | .B strtol | |
82 | returns | |
83 | .BR LONG_MAX . | |
84 | In both cases, | |
85 | .B errno | |
86 | is set to | |
87 | .BR ERANGE . | |
88 | .SH ERRORS | |
89 | .TP | |
90 | [ERANGE] | |
91 | The given string was out of range; the value converted has been clamped. | |
92 | .SH SEE ALSO | |
93 | atof(3), atoi(3), atol(3), strtod(3), strtoul(3) | |
94 | .SH STANDARDS | |
95 | .B Strtol | |
96 | conforms to ANSI X3.159-1989 (``ANSI C''). | |
97 | .SH BUGS | |
98 | Ignores the current locale. |