]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strtol.3
Import of man-pages 1.70
[thirdparty/man-pages.git] / man3 / strtol.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sun Jul 25 10:53:39 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Added correction due to nsd@bbc.com (Nick Duffek) - aeb, 950610
29 .TH STRTOL 3 2002-05-30 "GNU" "Linux Programmer's Manual"
30 .SH NAME
31 strtol, strtoll, strtoq \- convert a string to a long integer
32 .SH SYNOPSIS
33 .nf
34 .B #include <stdlib.h>
35 .sp
36 .BI "long int"
37 .BI "strtol(const char *" nptr ", char **" endptr ", int " base );
38 .sp
39 .BI "long long int"
40 .BI "strtoll(const char *" nptr ", char **" endptr ", int " base );
41 .fi
42 .SH DESCRIPTION
43 The \fBstrtol()\fP function converts the initial part of the string
44 in \fInptr\fP to a long integer value according to the given \fIbase\fP,
45 which must be between 2 and 36 inclusive, or be the special value 0.
46 .PP
47 The string must begin with an arbitrary amount of white space (as
48 determined by
49 .BR isspace (3))
50 followed by a single optional `+' or `-'
51 sign. If \fIbase\fP is zero or 16, the string may then include a
52 `0x' prefix, and the number will be read in base 16; otherwise, a
53 zero \fIbase\fP is taken as 10 (decimal) unless the next character
54 is `0', in which case it is taken as 8 (octal).
55 .PP
56 The remainder of the string is converted to a long int value
57 in the obvious manner, stopping at the first character which is not a
58 valid digit in the given base. (In bases above 10, the letter `A' in
59 either upper or lower case represents 10, `B' represents 11, and so
60 forth, with `Z' representing 35.)
61 .PP
62 If \fIendptr\fP is not NULL, \fBstrtol()\fP stores the address of the
63 first invalid character in \fI*endptr\fP. If there were no digits at
64 all, \fBstrtol()\fP stores the original value of \fInptr\fP in
65 \fI*endptr\fP (and returns 0).
66 In particular, if \fI*nptr\fP is not `\\0' but \fI**endptr\fP
67 is `\\0' on return, the entire string is valid.
68 .PP
69 The
70 .B strtoll()
71 function works just like the
72 .B strtol()
73 function but returns a long long integer value.
74 .SH "RETURN VALUE"
75 The \fBstrtol()\fP function returns the result of the conversion,
76 unless the value would underflow or overflow. If an underflow occurs,
77 \fBstrtol()\fP returns LONG_MIN. If an overflow occurs, \fBstrtol()\fP
78 returns LONG_MAX. In both cases, \fIerrno\fP is set to ERANGE.
79 Precisely the same holds for
80 .B strtoll()
81 (with LLONG_MIN and LLONG_MAX instead of LONG_MIN and LONG_MAX).
82 .SH ERRORS
83 .TP
84 .B EINVAL
85 (not in C99)
86 The given
87 .I base
88 contains an unsupported value.
89 .TP
90 .B ERANGE
91 The resulting value was out of range.
92 .LP
93 The implementation may also set \fIerrno\fP to \fBEINVAL\fP in case
94 no conversion was performed (no digits seen, and 0 returned).
95 .SH NOTES
96 In locales other than the "C" locale, also other strings may be accepted.
97 (For example, the thousands separator of the current locale may be
98 supported.)
99 .LP
100 BSD also has
101 .sp
102 .in +4n
103 .nf
104 .BI "quad_t"
105 .BI "strtoq(const char *" nptr ", char **" endptr ", int " base );
106 .sp
107 .in -4n
108 .fi
109 with completely analogous definition.
110 Depending on the wordsize of the current architecture, this
111 may be equivalent to
112 .B strtoll()
113 or to
114 .BR strtol() .
115 .SH "CONFORMING TO"
116 .B strtol()
117 conforms to SVID 3, BSD 4.3, ISO 9899 (C99) and POSIX, and
118 .B strtoll()
119 to ISO 9899 (C99) and POSIX 1003.1-2001.
120 .SH "SEE ALSO"
121 .BR atof (3),
122 .BR atoi (3),
123 .BR atol (3),
124 .BR strtod (3),
125 .BR strtoul (3)