|
|
1.1 root 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: .\" 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.
20: .\"
21: .\" @(#)strtol.3 5.1 (Berkeley) 5/15/90
22: .\"
23: .TH STRTOL 3 "May 15, 1990"
24: .UC 7
25: .SH NAME
26: strtol \- convert a string to a long integer
27: .SH SYNOPSIS
28: .B #include <stdlib.h>
29: .br
30: .B #include <limits.h>
31: .PP
32: .B "long strtol(char *nptr, char **endptr, int base);
33: .SH DESCRIPTION
34: .B Strtol
35: converts the string in
36: .I nptr
37: to a
38: .B long
39: value according to the given
40: .IR base ,
41: which must be between 2 and 36 inclusive,
42: or be the special value 0.
43: .PP
44: The string may begin with an arbitrary amount of white space
45: (as determined by
46: .BR isspace ;
47: see
48: .IR ctype (3)),
49: followed by a single optional `+' or `-' sign.
50: If
51: .I base
52: is zero or 16,
53: the string may then include a `0x' prefix,
54: and the number will be read in base 16; otherwise, a zero
55: .I base
56: is taken as 10 (decimal) unless the next character is `0',
57: in which case it is taken as 8 (octal).
58: .PP
59: The remainder of the string is converted to a
60: .B long
61: value in the obvious manner,
62: stopping at the first character which is not a valid digit
63: in the given base.
64: (In bases above 10, the letter `A' in either upper or lower case
65: represents 10, `B' represents 11, and so forth, with `Z' representing 35.)
66: .PP
67: If
68: .I endptr
69: is non nil,
70: .B strtol
71: stores the address of the first invalid character in
72: .IR *endptr .
73: If there were no digits at all, however,
74: .B strtol
75: stores the original value of
76: .I nptr
77: in
78: .IR *endptr .
79: (Thus, if
80: .I *nptr
81: is not '\e0' but
82: .IR **endptr
83: is '\e0' on return, the entire string was valid.)
84: .SH RETURN VALUE
85: .B Strtol
86: returns the result of the conversion,
87: unless the value would underflow or overflow.
88: If an underflow occurs,
89: .B strtol
90: returns
91: .BR LONG_MIN .
92: If an overflow occurs,
93: .B strtol
94: returns
95: .BR LONG_MAX .
96: In both cases,
97: .B errno
98: is set to
99: .BR ERANGE .
100: .SH ERRORS
101: .TP
102: [ERANGE]
103: The given string was out of range; the value converted has been clamped.
104: .SH SEE ALSO
105: atof(3), atoi(3), atol(3), strtod(3), strtoul(3)
106: .SH STANDARDS
107: .B Strtol
108: conforms to ANSI X3.159-1989 (``ANSI C'').
109: .SH BUGS
110: Ignores the current locale.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.