summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtol.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/strtol.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/strtol.3')
-rw-r--r--src/lib/libc/stdlib/strtol.351
1 files changed, 30 insertions, 21 deletions
diff --git a/src/lib/libc/stdlib/strtol.3 b/src/lib/libc/stdlib/strtol.3
index c0a60979d9..742be4cbb7 100644
--- a/src/lib/libc/stdlib/strtol.3
+++ b/src/lib/libc/stdlib/strtol.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: strtol.3,v 1.24 2013/08/14 06:32:28 jmc Exp $ 32.\" $OpenBSD: strtol.3,v 1.25 2014/09/14 14:32:44 schwarze Exp $
33.\" 33.\"
34.Dd $Mdocdate: August 14 2013 $ 34.Dd $Mdocdate: September 14 2014 $
35.Dt STRTOL 3 35.Dt STRTOL 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
@@ -45,14 +45,11 @@
45.In stdlib.h 45.In stdlib.h
46.Ft long 46.Ft long
47.Fn strtol "const char *nptr" "char **endptr" "int base" 47.Fn strtol "const char *nptr" "char **endptr" "int base"
48.Pp
49.Ft long long 48.Ft long long
50.Fn strtoll "const char *nptr" "char **endptr" "int base" 49.Fn strtoll "const char *nptr" "char **endptr" "int base"
51.Pp
52.In inttypes.h 50.In inttypes.h
53.Ft intmax_t 51.Ft intmax_t
54.Fn strtoimax "const char *nptr" "char **endptr" "int base" 52.Fn strtoimax "const char *nptr" "char **endptr" "int base"
55.Pp
56.In sys/types.h 53.In sys/types.h
57.In limits.h 54.In limits.h
58.In stdlib.h 55.In stdlib.h
@@ -64,21 +61,21 @@ The
64function converts the string in 61function converts the string in
65.Fa nptr 62.Fa nptr
66to a 63to a
67.Li long 64.Vt long
68value. 65value.
69The 66The
70.Fn strtoll 67.Fn strtoll
71function converts the string in 68function converts the string in
72.Fa nptr 69.Fa nptr
73to a 70to a
74.Li long long 71.Vt long long
75value. 72value.
76The 73The
77.Fn strtoimax 74.Fn strtoimax
78function converts the string in 75function converts the string in
79.Fa nptr 76.Fa nptr
80to an 77to an
81.Li intmax_t 78.Vt intmax_t
82value. 79value.
83The 80The
84.Fn strtoq 81.Fn strtoq
@@ -108,10 +105,10 @@ is taken as 10 (decimal) unless the next character is
108in which case it is taken as 8 (octal). 105in which case it is taken as 8 (octal).
109.Pp 106.Pp
110The remainder of the string is converted to a 107The remainder of the string is converted to a
111.Li long , 108.Vt long ,
112.Li long long , 109.Vt long long ,
113or 110or
114.Li intmax_t , 111.Vt intmax_t
115value in the obvious manner, 112value in the obvious manner,
116stopping at the first character which is not a valid digit 113stopping at the first character which is not a valid digit
117in the given base. 114in the given base.
@@ -151,14 +148,7 @@ The
151.Fn strtoimax , 148.Fn strtoimax ,
152and 149and
153.Fn strtoq 150.Fn strtoq
154functions return the result of the conversion, 151functions return the result of the conversion.
155unless the value would underflow or overflow.
156If no conversion could be performed, 0 is returned;
157the global variable
158.Va errno
159is also set to
160.Er EINVAL ,
161though this is not portable across all platforms.
162If overflow or underflow occurs, 152If overflow or underflow occurs,
163.Va errno 153.Va errno
164is set to 154is set to
@@ -171,6 +161,14 @@ and the function return value is as follows:
171.It Fn strtoimax Ta Dv INTMAX_MIN Ta Dv INTMAX_MAX 161.It Fn strtoimax Ta Dv INTMAX_MIN Ta Dv INTMAX_MAX
172.It Fn strtoq Ta Dv LLONG_MIN Ta Dv LLONG_MAX 162.It Fn strtoq Ta Dv LLONG_MIN Ta Dv LLONG_MAX
173.El 163.El
164.Pp
165If there is no valid digit, 0 is returned.
166If
167.Ar base
168is invalid, 0 is returned and the global variable
169.Va errno
170is set to
171.Er EINVAL .
174.Sh EXAMPLES 172.Sh EXAMPLES
175Ensuring that a string is a valid number (i.e., in range and containing no 173Ensuring that a string is a valid number (i.e., in range and containing no
176trailing characters) requires clearing 174trailing characters) requires clearing
@@ -212,9 +210,9 @@ If
212is being used instead of 210is being used instead of
213.Xr atoi 3 , 211.Xr atoi 3 ,
214error checking is further complicated because the desired return value is an 212error checking is further complicated because the desired return value is an
215.Li int 213.Vt int
216rather than a 214rather than a
217.Li long ; 215.Vt long ;
218however, on some architectures integers and long integers are the same size. 216however, on some architectures integers and long integers are the same size.
219Thus the following is necessary: 217Thus the following is necessary:
220.Bd -literal -offset indent 218.Bd -literal -offset indent
@@ -235,6 +233,10 @@ ival = lval;
235.Ed 233.Ed
236.Sh ERRORS 234.Sh ERRORS
237.Bl -tag -width Er 235.Bl -tag -width Er
236.It Bq Er EINVAL
237The value of
238.Ar base
239was neither between 2 and 36 inclusive nor the special value 0.
238.It Bq Er ERANGE 240.It Bq Er ERANGE
239The given string was out of range; the value converted has been clamped. 241The given string was out of range; the value converted has been clamped.
240.El 242.El
@@ -255,6 +257,13 @@ and
255.Fn strtoimax 257.Fn strtoimax
256functions conform to 258functions conform to
257.St -ansiC-99 . 259.St -ansiC-99 .
260Setting
261.Va errno
262to
263.Dv EINVAL
264is an extension to that standard required by
265.St -p1003.1-2008 .
266.Pp
258The 267The
259.Fn strtoq 268.Fn strtoq
260function is a 269function is a