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