summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtoul.3
diff options
context:
space:
mode:
authorschwarze <>2014-09-14 14:32:44 +0000
committerschwarze <>2014-09-14 14:32:44 +0000
commit942d3f7f21b3d5906968b93cbb26de97a8979084 (patch)
treee141a2122bc43678c51eb65a9ea85048a8ba2e68 /src/lib/libc/stdlib/strtoul.3
parent231db4657473247f753eff3dda736712538c9fd7 (diff)
downloadopenbsd-942d3f7f21b3d5906968b93cbb26de97a8979084.tar.gz
openbsd-942d3f7f21b3d5906968b93cbb26de97a8979084.tar.bz2
openbsd-942d3f7f21b3d5906968b93cbb26de97a8979084.zip
Do not claim that empty numbers set EINVAL, our implementation doesn't.
Mention that invalid bases do set EINVAL (as required by POSIX); this part of the change uses part of an earlier patch by millert@. Minor mdoc(7) cleanup and sync between the two pages while here. Feedback and ok jmc@ and millert@.
Diffstat (limited to 'src/lib/libc/stdlib/strtoul.3')
-rw-r--r--src/lib/libc/stdlib/strtoul.347
1 files changed, 31 insertions, 16 deletions
diff --git a/src/lib/libc/stdlib/strtoul.3 b/src/lib/libc/stdlib/strtoul.3
index 1353637d68..122ad7bb26 100644
--- a/src/lib/libc/stdlib/strtoul.3
+++ b/src/lib/libc/stdlib/strtoul.3
@@ -29,9 +29,9 @@
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
31.\" 31.\"
32.\" $OpenBSD: strtoul.3,v 1.22 2013/08/14 06:32:28 jmc Exp $ 32.\" $OpenBSD: strtoul.3,v 1.23 2014/09/14 14:32:44 schwarze Exp $
33.\" 33.\"
34.Dd $Mdocdate: August 14 2013 $ 34.Dd $Mdocdate: September 14 2014 $
35.Dt STRTOUL 3 35.Dt STRTOUL 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
@@ -61,21 +61,21 @@ The
61function converts the string in 61function converts the string in
62.Fa nptr 62.Fa nptr
63to an 63to an
64.Li unsigned long 64.Vt unsigned long
65value. 65value.
66The 66The
67.Fn strtoull 67.Fn strtoull
68function converts the string in 68function converts the string in
69.Fa nptr 69.Fa nptr
70to an 70to an
71.Li unsigned long long 71.Vt unsigned long long
72value. 72value.
73The 73The
74.Fn strtoumax 74.Fn strtoumax
75function converts the string in 75function converts the string in
76.Fa nptr 76.Fa nptr
77to a 77to a
78.Li umaxint_t 78.Vt umaxint_t
79value. 79value.
80The 80The
81.Fn strtouq 81.Fn strtouq
@@ -84,8 +84,7 @@ function is a deprecated equivalent of
84and is provided for backwards compatibility with legacy programs. 84and is provided for backwards compatibility with legacy programs.
85The conversion is done according to the given 85The conversion is done according to the given
86.Fa base , 86.Fa base ,
87which must be a number between 2 and 36 inclusive 87which must be a number between 2 and 36 inclusive or the special value 0.
88or the special value 0.
89If the string in 88If the string in
90.Fa nptr 89.Fa nptr
91represents a negative number, it will be converted to its unsigned equivalent. 90represents a negative number, it will be converted to its unsigned equivalent.
@@ -111,9 +110,12 @@ is taken as 10 (decimal) unless the next character is
111in which case it is taken as 8 (octal). 110in which case it is taken as 8 (octal).
112.Pp 111.Pp
113The remainder of the string is converted to an 112The remainder of the string is converted to an
114.Li unsigned long 113.Vt unsigned long ,
115value in the obvious manner, stopping at the end of the string 114.Vt unsigned long long ,
116or at the first character that does not produce a valid digit 115or
116.Vt uintmax_t
117value in the obvious manner,
118stopping at the first character which is not a valid digit
117in the given base. 119in the given base.
118(In bases above 10, the letter 120(In bases above 10, the letter
119.Ql A 121.Ql A
@@ -172,12 +174,6 @@ and the global variable
172.Va errno 174.Va errno
173is set to 175is set to
174.Er ERANGE . 176.Er ERANGE .
175If no conversion could be performed, 0 is returned;
176the global variable
177.Va errno
178is also set to
179.Er EINVAL ,
180though this is not portable across all platforms.
181.Pp 177.Pp
182There is no way to determine if 178There is no way to determine if
183.Fn strtoul 179.Fn strtoul
@@ -185,6 +181,14 @@ has processed a negative number (and returned an unsigned value) short of
185examining the string in 181examining the string in
186.Fa nptr 182.Fa nptr
187directly. 183directly.
184.Pp
185If there is no valid digit, 0 is returned.
186If
187.Ar base
188is invalid, 0 is returned and the global variable
189.Va errno
190is set to
191.Er EINVAL .
188.Sh EXAMPLES 192.Sh EXAMPLES
189Ensuring that a string is a valid number (i.e., in range and containing no 193Ensuring that a string is a valid number (i.e., in range and containing no
190trailing characters) requires clearing 194trailing characters) requires clearing
@@ -222,6 +226,10 @@ alternately, use
222.Xr sscanf 3 . 226.Xr sscanf 3 .
223.Sh ERRORS 227.Sh ERRORS
224.Bl -tag -width Er 228.Bl -tag -width Er
229.It Bq Er EINVAL
230The value of
231.Ar base
232was neither between 2 and 36 inclusive nor the special value 0.
225.It Bq Er ERANGE 233.It Bq Er ERANGE
226The given string was out of range; the value converted has been clamped. 234The given string was out of range; the value converted has been clamped.
227.El 235.El
@@ -236,6 +244,13 @@ and
236.Fn strtoumax 244.Fn strtoumax
237functions conform to 245functions conform to
238.St -ansiC-99 . 246.St -ansiC-99 .
247Setting
248.Va errno
249to
250.Dv EINVAL
251is an extension to that standard required by
252.St -p1003.1-2008 .
253.Pp
239The 254The
240.Fn strtouq 255.Fn strtouq
241function is a 256function is a