summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/strtol.3
diff options
context:
space:
mode:
authormillert <>2006-01-13 17:58:09 +0000
committermillert <>2006-01-13 17:58:09 +0000
commit978c3a7e8d11b1e84147c6da7fa5908182dbf6f1 (patch)
tree302bb25ba83f38b5dc042943f23d0ff80c5d29d5 /src/lib/libc/stdlib/strtol.3
parent1e745892f72a6490f4783b86b64e88e0c5c4bf61 (diff)
downloadopenbsd-978c3a7e8d11b1e84147c6da7fa5908182dbf6f1.tar.gz
openbsd-978c3a7e8d11b1e84147c6da7fa5908182dbf6f1.tar.bz2
openbsd-978c3a7e8d11b1e84147c6da7fa5908182dbf6f1.zip
Add lldiv(), imaxabs(), imaxdiv(), strtoimax() and strtoumax()
Diffstat (limited to 'src/lib/libc/stdlib/strtol.3')
-rw-r--r--src/lib/libc/stdlib/strtol.368
1 files changed, 39 insertions, 29 deletions
diff --git a/src/lib/libc/stdlib/strtol.3 b/src/lib/libc/stdlib/strtol.3
index 3f5375c5e3..1ba936dd0d 100644
--- a/src/lib/libc/stdlib/strtol.3
+++ b/src/lib/libc/stdlib/strtol.3
@@ -29,27 +29,30 @@
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.13 2003/06/02 20:18:38 millert Exp $ 32.\" $OpenBSD: strtol.3,v 1.14 2006/01/13 17:58:09 millert Exp $
33.\" 33.\"
34.Dd June 25, 1992 34.Dd January 3, 2006
35.Dt STRTOL 3 35.Dt STRTOL 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
38.Nm strtol , 38.Nm strtol ,
39.Nm strtoll , 39.Nm strtoll ,
40.Nm strtoq 40.Nm strtoimax ,
41.Nd "convert string value to a long or long long integer" 41.Nm strtoq ,
42.Nd "convert string value to a long, long long or intmax_t integer"
42.Sh SYNOPSIS 43.Sh SYNOPSIS
43.Fd #include <stdlib.h> 44.Fd #include <stdlib.h>
44.Fd #include <limits.h> 45.Fd #include <limits.h>
45.Ft long 46.Ft long
46.Fn strtol "const char *nptr" "char **endptr" "int base" 47.Fn strtol "const char *nptr" "char **endptr" "int base"
47.Pp 48.Pp
48.Fd #include <stdlib.h>
49.Fd #include <limits.h>
50.Ft long long 49.Ft long long
51.Fn strtoll "const char *nptr" "char **endptr" "int base" 50.Fn strtoll "const char *nptr" "char **endptr" "int base"
52.Pp 51.Pp
52.Fd #include <inttypes.h>
53.Ft intmax_t
54.Fn strtoimax "const char *nptr" "char **endptr" "int base"
55.Pp
53.Fd #include <sys/types.h> 56.Fd #include <sys/types.h>
54.Fd #include <stdlib.h> 57.Fd #include <stdlib.h>
55.Fd #include <limits.h> 58.Fd #include <limits.h>
@@ -71,6 +74,13 @@ to a
71.Li long long 74.Li long long
72value. 75value.
73The 76The
77.Fn strtoimax
78function converts the string in
79.Fa nptr
80to an
81.Li intmax_t
82value.
83The
74.Fn strtoq 84.Fn strtoq
75function is a deprecated equivalent of 85function is a deprecated equivalent of
76.Fn strtoll 86.Fn strtoll
@@ -98,7 +108,10 @@ is taken as 10 (decimal) unless the next character is
98in which case it is taken as 8 (octal). 108in which case it is taken as 8 (octal).
99.Pp 109.Pp
100The remainder of the string is converted to a 110The remainder of the string is converted to a
101.Li long 111.Li long ,
112.Li long long ,
113or
114.Li intmax_t ,
102value in the obvious manner, 115value in the obvious manner,
103stopping at the first character which is not a valid digit 116stopping at the first character which is not a valid digit
104in the given base. 117in the given base.
@@ -133,29 +146,25 @@ is
133on return, the entire string was valid.) 146on return, the entire string was valid.)
134.Sh RETURN VALUES 147.Sh RETURN VALUES
135The 148The
136.Fn strtol 149.Fn strtol ,
137function returns the result of the conversion, 150.Fn strtoll ,
151.Fn strtoimax ,
152and
153.Fn strtoq
154functions returns the result of the conversion,
138unless the value would underflow or overflow. 155unless the value would underflow or overflow.
139If an underflow occurs, 156If overflow or underflow occurs,
140.Fn strtol
141returns
142.Dv LONG_MIN .
143If an overflow occurs,
144.Fn strtol
145returns
146.Dv LONG_MAX .
147In both cases,
148.Va errno 157.Va errno
149is set to 158is set to
150.Er ERANGE . 159.Er ERANGE
151.Pp 160and the function return value is as follows:
152The 161.Bl -column -offset indent "strtoimax" "overflow" "underflow"
153.Fn strtoll 162.It Sy Function Ta Sy overflow Ta Sy underflow
154function has identical return values except that 163.It Fn strtol Ta Dv LONG_MIN Ta Dv LONG_MAX
155.Dv LLONG_MIN 164.It Fn strtoll Ta Dv LLONG_MIN Ta Dv LLONG_MAX
156and 165.It Fn strtoimax Ta Dv INTMAX_MIN Ta Dv INTMAX_MAX
157.Dv LLONG_MAX 166.It Fn strtoq Ta Dv LLONG_MIN Ta Dv LLONG_MAX
158are used to indicate underflow and overflow respectively. 167.El
159.Sh EXAMPLES 168.Sh EXAMPLES
160Ensuring that a string is a valid number (i.e., in range and containing no 169Ensuring that a string is a valid number (i.e., in range and containing no
161trailing characters) requires clearing 170trailing characters) requires clearing
@@ -233,9 +242,10 @@ The given string was out of range; the value converted has been clamped.
233.Xr strtoul 3 242.Xr strtoul 3
234.Sh STANDARDS 243.Sh STANDARDS
235The 244The
236.Fn strtol 245.Fn strtol ,
246.Fn strtoll ,
237and 247and
238.Fn strtoll 248.Fn strtoimax
239functions conform to 249functions conform to
240.St -ansiC-99 . 250.St -ansiC-99 .
241The 251The