1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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"
31 strtol, strtoll, strtoq \- convert a string to a long integer
34 .B #include <stdlib.h>
37 .BI "strtol(const char *" nptr ", char **" endptr ", int " base );
40 .BI "strtoll(const char *" nptr ", char **" endptr ", int " base );
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.
47 The string must begin with an arbitrary amount of white space (as
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).
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.)
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.
71 function works just like the
73 function but returns a long long integer 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
81 (with LLONG_MIN and LLONG_MAX instead of LONG_MIN and LONG_MAX).
88 contains an unsupported value.
91 The resulting value was out of range.
93 The implementation may also set \fIerrno\fP to \fBEINVAL\fP in case
94 no conversion was performed (no digits seen, and 0 returned).
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
105 .BI "strtoq(const char *" nptr ", char **" endptr ", int " base );
109 with completely analogous definition.
110 Depending on the wordsize of the current architecture, this
117 conforms to SVID 3, BSD 4.3, ISO 9899 (C99) and POSIX, and
119 to ISO 9899 (C99) and POSIX 1003.1-2001.