225 lines
9.5 KiB
HTML
225 lines
9.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>strtol</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="strtol"></a> <a name="tag_03_743"></a><!-- strtol -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_743_01"></a>NAME</h4>
|
|
|
|
<blockquote>strtol, strtoll - convert a string to a long integer</blockquote>
|
|
|
|
<h4><a name="tag_03_743_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/stdlib.h.html">stdlib.h</a>><br>
|
|
<br>
|
|
long strtol(const char *restrict</tt> <i>str</i><tt>, char **restrict</tt> <i>endptr</i><tt>, int</tt> <i>base</i><tt>);<br>
|
|
long long strtoll(const char *restrict</tt> <i>str</i><tt>, char **restrict</tt> <i>endptr</i><tt>,<br>
|
|
int</tt> <i>base</i><tt>)<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
|
|
border="0"> The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the
|
|
requirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to
|
|
the ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div>
|
|
|
|
<p>These functions shall convert the initial portion of the string pointed to by <i>str</i> to a type <b>long</b> and <b>long
|
|
long</b> representation, respectively. First, they decompose the input string into three parts:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>An initial, possibly empty, sequence of white-space characters (as specified by <a href=
|
|
"../functions/isspace.html"><i>isspace</i>()</a>)</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A subject sequence interpreted as an integer represented in some radix determined by the value of <i>base</i></p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A final string of one or more unrecognized characters, including the terminating null byte of the input string.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>Then they shall attempt to convert the subject sequence to an integer, and return the result.</p>
|
|
|
|
<p>If the value of <i>base</i> is 0, the expected form of the subject sequence is that of a decimal constant, octal constant, or
|
|
hexadecimal constant, any of which may be preceded by a <tt>'+'</tt> or <tt>'-'</tt> sign. A decimal constant begins with a
|
|
non-zero digit, and consists of a sequence of decimal digits. An octal constant consists of the prefix <tt>'0'</tt> optionally
|
|
followed by a sequence of the digits <tt>'0'</tt> to <tt>'7'</tt> only. A hexadecimal constant consists of the prefix 0x or 0X
|
|
followed by a sequence of the decimal digits and letters <tt>'a'</tt> (or <tt>'A'</tt> ) to <tt>'f'</tt> (or <tt>'F'</tt> ) with
|
|
values 10 to 15 respectively.</p>
|
|
|
|
<p>If the value of <i>base</i> is between 2 and 36, the expected form of the subject sequence is a sequence of letters and digits
|
|
representing an integer with the radix specified by <i>base</i>, optionally preceded by a <tt>'+'</tt> or <tt>'-'</tt> sign. The
|
|
letters from <tt>'a'</tt> (or <tt>'A'</tt> ) to <tt>'z'</tt> (or <tt>'Z'</tt> ) inclusive are ascribed the values 10 to 35; only
|
|
letters whose ascribed values are less than that of <i>base</i> are permitted. If the value of <i>base</i> is 16, the characters 0x
|
|
or 0X may optionally precede the sequence of letters and digits, following the sign if present.</p>
|
|
|
|
<p>The subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-white-space
|
|
character that is of the expected form. The subject sequence shall contain no characters if the input string is empty or consists
|
|
entirely of white-space characters, or if the first non-white-space character is other than a sign or a permissible letter or
|
|
digit.</p>
|
|
|
|
<p>If the subject sequence has the expected form and the value of <i>base</i> is 0, the sequence of characters starting with the
|
|
first digit shall be interpreted as an integer constant. If the subject sequence has the expected form and the value of <i>base</i>
|
|
is between 2 and 36, it shall be used as the base for conversion, ascribing to each letter its value as given above. If the subject
|
|
sequence begins with a minus sign, the value resulting from the conversion shall be negated. A pointer to the final string shall be
|
|
stored in the object pointed to by <i>endptr</i>, provided that <i>endptr</i> is not a null pointer.</p>
|
|
|
|
<p>In other than the C <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> or POSIX <img src="../images/opt-end.gif" alt="[Option End]" border="0"> locales, other
|
|
implementation-defined subject sequences may be accepted.</p>
|
|
|
|
<p>If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of <i>str</i> is
|
|
stored in the object pointed to by <i>endptr</i>, provided that <i>endptr</i> is not a null pointer.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> The
|
|
<i>strtol</i>() function shall not change the setting of <i>errno</i> if successful.</p>
|
|
|
|
<p>Since 0, {LONG_MIN} or {LLONG_MIN}, and {LONG_MAX} or {LLONG_MAX} are returned on error and are also valid returns on success,
|
|
an application wishing to check for error situations should set <i>errno</i> to 0, then call <i>strtol</i>() or <i>strtoll</i>(),
|
|
then check <i>errno</i>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, these functions shall return the converted value, if any. If no conversion could be performed, 0
|
|
shall be returned <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
|
|
border="0"> and <i>errno</i> may be set to [EINVAL]. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p>If the correct value is outside the range of representable values, {LONG_MIN}, {LONG_MAX}, {LLONG_MIN}, or {LLONG_MAX} shall be
|
|
returned (according to the sign of the value), and <i>errno</i> set to [ERANGE].</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>These functions shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ERANGE]</dt>
|
|
|
|
<dd>The value to be returned is not representable.</dd>
|
|
</dl>
|
|
|
|
<p>These functions may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The value of <i>base</i> is not supported. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_743_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="isalpha.html"><i>isalpha</i>()</a> , <a href="scanf.html"><i>scanf</i>()</a> , <a href=
|
|
"strtod.html"><i>strtod</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/stdlib.h.html"><i><stdlib.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>The DESCRIPTION is updated to indicate that <i>errno</i> is not changed if the function is successful.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_743_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>Extensions beyond the ISO C standard are marked.</p>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>In the RETURN VALUE and ERRORS sections, the [EINVAL] optional error condition is added if no conversion could be performed.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following changes are made for alignment with the ISO/IEC 9899:1999 standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The <i>strtol</i>() prototype is updated.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The <i>strtoll</i>() function is added.</p>
|
|
</li>
|
|
</ul>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|