Files
2024-02-19 00:21:47 -05:00

232 lines
9.9 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>strtoul</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="strtoul"></a> <a name="tag_03_746"></a><!-- strtoul -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_746_01"></a>NAME</h4>
<blockquote>strtoul, strtoull - convert a string to an unsigned long</blockquote>
<h4><a name="tag_03_746_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/stdlib.h.html">stdlib.h</a>&gt;<br>
<br>
unsigned long strtoul(const char *restrict</tt> <i>str</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char **restrict</tt> <i>endptr</i><tt>, int</tt> <i>base</i><tt>);<br>
unsigned long long strtoull(const char *restrict</tt> <i>str</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char **restrict</tt> <i>endptr</i><tt>, int</tt> <i>base</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_746_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&nbsp;C standard. Any conflict between the
requirements described here and the ISO&nbsp;C standard is unintentional. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 defers to
the ISO&nbsp;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>unsigned long</b> and
<b>unsigned 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 unsigned 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"> &nbsp;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 shall be performed; the value of <i>str</i>
shall be 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>strtoul</i>() function shall not change the setting of <i>errno</i> if successful.</p>
<p>Since 0, {ULONG_MAX}, and {ULLONG_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>strtoul</i>() or <i>strtoull</i>(), then check <i>errno</i>.
<img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_03_746_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"> &nbsp;and <i>errno</i> may be set to [EINVAL]. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> If the
correct value is outside the range of representable values, {ULONG_MAX} or {ULLONG_MAX} shall be returned and <i>errno</i> set to
[ERANGE].</p>
</blockquote>
<h4><a name="tag_03_746_05"></a>ERRORS</h4>
<blockquote>
<p>These functions shall 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>
<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"> No
conversion could be performed. <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_746_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_746_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_746_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_746_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_746_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> , <a href="strtol.html"><i>strtol</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/stdlib.h.html"><i>&lt;stdlib.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_746_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4. Derived from the ANSI&nbsp;C standard.</p>
</blockquote>
<h4><a name="tag_03_746_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_746_13"></a>Issue 6</h4>
<blockquote>
<p>Extensions beyond the ISO&nbsp;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>The [EINVAL] error condition is added for when the value of <i>base</i> is not supported.</p>
<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&nbsp;9899:1999 standard:</p>
<ul>
<li>
<p>The <i>strtoul</i>() prototype is updated.</p>
</li>
<li>
<p>The <i>strtoull</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 &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; 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>