|
Packit |
7cfc04 |
'\" et
|
|
Packit |
7cfc04 |
.TH STRTOL "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH PROLOG
|
|
Packit |
7cfc04 |
This manual page is part of the POSIX Programmer's Manual.
|
|
Packit |
7cfc04 |
The Linux implementation of this interface may differ (consult
|
|
Packit |
7cfc04 |
the corresponding Linux manual page for details of Linux behavior),
|
|
Packit |
7cfc04 |
or the interface may not be implemented on Linux.
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
strtol,
|
|
Packit |
7cfc04 |
strtoll
|
|
Packit |
7cfc04 |
\(em convert a string to a long integer
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
#include <stdlib.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
long strtol(const char *restrict \fIstr\fP, char **restrict \fIendptr\fP, int \fIbase\fP);
|
|
Packit |
7cfc04 |
long long strtoll(const char *restrict \fIstr\fP, char **restrict \fIendptr\fP,
|
|
Packit |
7cfc04 |
int \fIbase\fP)
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The functionality described on this reference page is aligned with the
|
|
Packit |
7cfc04 |
ISO\ C standard. Any conflict between the requirements described here and the
|
|
Packit |
7cfc04 |
ISO\ C standard is unintentional. This volume of POSIX.1\(hy2008 defers to the ISO\ C standard.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
These functions shall convert the initial portion of the string pointed
|
|
Packit |
7cfc04 |
to by
|
|
Packit |
7cfc04 |
.IR str
|
|
Packit |
7cfc04 |
to a type
|
|
Packit |
7cfc04 |
.BR "long"
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR "long long"
|
|
Packit |
7cfc04 |
representation, respectively. First, they decompose the input string
|
|
Packit |
7cfc04 |
into three parts:
|
|
Packit |
7cfc04 |
.IP " 1." 4
|
|
Packit |
7cfc04 |
An initial, possibly empty, sequence of white-space characters (as
|
|
Packit |
7cfc04 |
specified by
|
|
Packit |
7cfc04 |
\fIisspace\fR())
|
|
Packit |
7cfc04 |
.IP " 2." 4
|
|
Packit |
7cfc04 |
A subject sequence interpreted as an integer represented in some radix
|
|
Packit |
7cfc04 |
determined by the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
.IP " 3." 4
|
|
Packit |
7cfc04 |
A final string of one or more unrecognized characters, including
|
|
Packit |
7cfc04 |
the terminating NUL character of the input string.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
Then they shall attempt to convert the subject sequence to an
|
|
Packit |
7cfc04 |
integer, and return the result.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is 0, the expected form of the subject sequence is that of a decimal
|
|
Packit |
7cfc04 |
constant, octal constant, or hexadecimal constant, any of which may be
|
|
Packit |
7cfc04 |
preceded by a
|
|
Packit |
7cfc04 |
.BR '+'
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.BR '\(mi'
|
|
Packit |
7cfc04 |
sign. A decimal constant begins with a non-zero digit, and consists of
|
|
Packit |
7cfc04 |
a sequence of decimal digits. An octal constant consists of the prefix
|
|
Packit |
7cfc04 |
.BR '0'
|
|
Packit |
7cfc04 |
optionally followed by a sequence of the digits
|
|
Packit |
7cfc04 |
.BR '0'
|
|
Packit |
7cfc04 |
to
|
|
Packit |
7cfc04 |
.BR '7'
|
|
Packit |
7cfc04 |
only. A hexadecimal constant consists of the prefix 0x or 0X followed
|
|
Packit |
7cfc04 |
by a sequence of the decimal digits and letters
|
|
Packit |
7cfc04 |
.BR 'a'
|
|
Packit |
7cfc04 |
(or
|
|
Packit |
7cfc04 |
.BR 'A' )
|
|
Packit |
7cfc04 |
to
|
|
Packit |
7cfc04 |
.BR 'f'
|
|
Packit |
7cfc04 |
(or
|
|
Packit |
7cfc04 |
.BR 'F' )
|
|
Packit |
7cfc04 |
with values 10 to 15 respectively.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is between 2 and 36, the expected form of the subject sequence is a
|
|
Packit |
7cfc04 |
sequence of letters and digits representing an integer with the radix
|
|
Packit |
7cfc04 |
specified by
|
|
Packit |
7cfc04 |
.IR base ,
|
|
Packit |
7cfc04 |
optionally preceded by a
|
|
Packit |
7cfc04 |
.BR '+'
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.BR '\(mi'
|
|
Packit |
7cfc04 |
sign. The letters from
|
|
Packit |
7cfc04 |
.BR 'a'
|
|
Packit |
7cfc04 |
(or
|
|
Packit |
7cfc04 |
.BR 'A' )
|
|
Packit |
7cfc04 |
to
|
|
Packit |
7cfc04 |
.BR 'z'
|
|
Packit |
7cfc04 |
(or
|
|
Packit |
7cfc04 |
.BR 'Z' )
|
|
Packit |
7cfc04 |
inclusive are ascribed the values 10 to 35; only letters whose ascribed
|
|
Packit |
7cfc04 |
values are less than that of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
are permitted. If the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is 16, the characters 0x or 0X may optionally precede the sequence of
|
|
Packit |
7cfc04 |
letters and digits, following the sign if present.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The subject sequence is defined as the longest initial subsequence of
|
|
Packit |
7cfc04 |
the input string, starting with the first non-white-space character
|
|
Packit |
7cfc04 |
that is of the expected form. The subject sequence shall contain no
|
|
Packit |
7cfc04 |
characters if the input string is empty or consists entirely of
|
|
Packit |
7cfc04 |
white-space characters, or if the first non-white-space character is
|
|
Packit |
7cfc04 |
other than a sign or a permissible letter or digit.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the subject sequence has the expected form and the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is 0, the sequence of characters starting with the first digit shall be
|
|
Packit |
7cfc04 |
interpreted as an integer constant. If the subject sequence has the
|
|
Packit |
7cfc04 |
expected form and the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is between 2 and 36, it shall be used as the base for conversion,
|
|
Packit |
7cfc04 |
ascribing to each letter its value as given above. If the subject
|
|
Packit |
7cfc04 |
sequence begins with a minus-sign, the value resulting from the
|
|
Packit |
7cfc04 |
conversion shall be negated. A pointer to the final string shall be
|
|
Packit |
7cfc04 |
stored in the object pointed to by
|
|
Packit |
7cfc04 |
.IR endptr ,
|
|
Packit |
7cfc04 |
provided that
|
|
Packit |
7cfc04 |
.IR endptr
|
|
Packit |
7cfc04 |
is not a null pointer.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
In other than the C
|
|
Packit |
7cfc04 |
or POSIX
|
|
Packit |
7cfc04 |
locales, other implementation-defined subject sequences may be
|
|
Packit |
7cfc04 |
accepted.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the subject sequence is empty or does not have the expected form, no
|
|
Packit |
7cfc04 |
conversion is performed; the value of
|
|
Packit |
7cfc04 |
.IR str
|
|
Packit |
7cfc04 |
shall be stored in the object pointed to by
|
|
Packit |
7cfc04 |
.IR endptr ,
|
|
Packit |
7cfc04 |
provided that
|
|
Packit |
7cfc04 |
.IR endptr
|
|
Packit |
7cfc04 |
is not a null pointer.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
These functions shall not change the setting of
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
if successful.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
Since 0,
|
|
Packit |
7cfc04 |
{LONG_MIN}
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
{LLONG_MIN},
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
{LONG_MAX}
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
{LLONG_MAX}
|
|
Packit |
7cfc04 |
are returned on error and are also valid returns on success, an
|
|
Packit |
7cfc04 |
application wishing to check for error situations should set
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
to 0, then call
|
|
Packit |
7cfc04 |
\fIstrtol\fR()
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
\fIstrtoll\fR(),
|
|
Packit |
7cfc04 |
then check
|
|
Packit |
7cfc04 |
.IR errno .
|
|
Packit |
7cfc04 |
.SH "RETURN VALUE"
|
|
Packit |
7cfc04 |
Upon successful completion, these functions shall return the converted
|
|
Packit |
7cfc04 |
value, if any. If no conversion could be performed, 0 shall be returned
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
may be set to
|
|
Packit |
7cfc04 |
.BR [EINVAL] .
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is not supported, 0 shall be returned and
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
shall be set to
|
|
Packit |
7cfc04 |
.BR [EINVAL] .
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the correct value is outside the range of representable values,
|
|
Packit |
7cfc04 |
{LONG_MIN},
|
|
Packit |
7cfc04 |
{LONG_MAX},
|
|
Packit |
7cfc04 |
{LLONG_MIN},
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
{LLONG_MAX}
|
|
Packit |
7cfc04 |
shall be returned (according to the sign of the value), and
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
set to
|
|
Packit |
7cfc04 |
.BR [ERANGE] .
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
These functions shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EINVAL
|
|
Packit |
7cfc04 |
The value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is not supported.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ERANGE
|
|
Packit |
7cfc04 |
The value to be returned is not representable.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
These functions may fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EINVAL
|
|
Packit |
7cfc04 |
No conversion could be performed.
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.IR "The following sections are informative."
|
|
Packit |
7cfc04 |
.SH EXAMPLES
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "APPLICATION USAGE"
|
|
Packit |
7cfc04 |
Since the value of
|
|
Packit |
7cfc04 |
.IR *endptr
|
|
Packit |
7cfc04 |
is unspecified if the value of
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
is not supported, applications should either ensure that
|
|
Packit |
7cfc04 |
.IR base
|
|
Packit |
7cfc04 |
has a supported value (0 or between 2 and 36) before the call, or check
|
|
Packit |
7cfc04 |
for an
|
|
Packit |
7cfc04 |
.BR [EINVAL]
|
|
Packit |
7cfc04 |
error before examining
|
|
Packit |
7cfc04 |
.IR *endptr .
|
|
Packit |
7cfc04 |
.SH RATIONALE
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "FUTURE DIRECTIONS"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "SEE ALSO"
|
|
Packit |
7cfc04 |
.IR "\fIfscanf\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fIisalpha\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fIstrtod\fR\^(\|)"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "\fB<stdlib.h>\fP"
|
|
Packit |
7cfc04 |
.SH COPYRIGHT
|
|
Packit |
7cfc04 |
Portions of this text are reprinted and reproduced in electronic form
|
|
Packit |
7cfc04 |
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
|
|
Packit |
7cfc04 |
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Packit |
7cfc04 |
Specifications Issue 7, Copyright (C) 2013 by the Institute of
|
|
Packit |
7cfc04 |
Electrical and Electronics Engineers, Inc and The Open Group.
|
|
Packit |
7cfc04 |
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
|
|
Packit |
7cfc04 |
event of any discrepancy between this version and the original IEEE and
|
|
Packit |
7cfc04 |
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
Packit |
7cfc04 |
is the referee document. The original Standard can be obtained online at
|
|
Packit |
7cfc04 |
http://www.unix.org/online.html .
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
Any typographical or formatting errors that appear
|
|
Packit |
7cfc04 |
in this page are most likely
|
|
Packit |
7cfc04 |
to have been introduced during the conversion of the source files to
|
|
Packit |
7cfc04 |
man page format. To report such errors, see
|
|
Packit |
7cfc04 |
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|