summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/strtol.3
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdlib/strtol.3')
-rw-r--r--lib/libc/stdlib/strtol.368
1 files changed, 39 insertions, 29 deletions
diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3
index 3f5375c5e3d..1ba936dd0d1 100644
--- a/lib/libc/stdlib/strtol.3
+++ b/lib/libc/stdlib/strtol.3
@@ -29,27 +29,30 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: strtol.3,v 1.13 2003/06/02 20:18:38 millert Exp $
+.\" $OpenBSD: strtol.3,v 1.14 2006/01/13 17:58:09 millert Exp $
.\"
-.Dd June 25, 1992
+.Dd January 3, 2006
.Dt STRTOL 3
.Os
.Sh NAME
.Nm strtol ,
.Nm strtoll ,
-.Nm strtoq
-.Nd "convert string value to a long or long long integer"
+.Nm strtoimax ,
+.Nm strtoq ,
+.Nd "convert string value to a long, long long or intmax_t integer"
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Fd #include <limits.h>
.Ft long
.Fn strtol "const char *nptr" "char **endptr" "int base"
.Pp
-.Fd #include <stdlib.h>
-.Fd #include <limits.h>
.Ft long long
.Fn strtoll "const char *nptr" "char **endptr" "int base"
.Pp
+.Fd #include <inttypes.h>
+.Ft intmax_t
+.Fn strtoimax "const char *nptr" "char **endptr" "int base"
+.Pp
.Fd #include <sys/types.h>
.Fd #include <stdlib.h>
.Fd #include <limits.h>
@@ -71,6 +74,13 @@ to a
.Li long long
value.
The
+.Fn strtoimax
+function converts the string in
+.Fa nptr
+to an
+.Li intmax_t
+value.
+The
.Fn strtoq
function is a deprecated equivalent of
.Fn strtoll
@@ -98,7 +108,10 @@ is taken as 10 (decimal) unless the next character is
in which case it is taken as 8 (octal).
.Pp
The remainder of the string is converted to a
-.Li long
+.Li long ,
+.Li long long ,
+or
+.Li intmax_t ,
value in the obvious manner,
stopping at the first character which is not a valid digit
in the given base.
@@ -133,29 +146,25 @@ is
on return, the entire string was valid.)
.Sh RETURN VALUES
The
-.Fn strtol
-function returns the result of the conversion,
+.Fn strtol ,
+.Fn strtoll ,
+.Fn strtoimax ,
+and
+.Fn strtoq
+functions returns the result of the conversion,
unless the value would underflow or overflow.
-If an underflow occurs,
-.Fn strtol
-returns
-.Dv LONG_MIN .
-If an overflow occurs,
-.Fn strtol
-returns
-.Dv LONG_MAX .
-In both cases,
+If overflow or underflow occurs,
.Va errno
is set to
-.Er ERANGE .
-.Pp
-The
-.Fn strtoll
-function has identical return values except that
-.Dv LLONG_MIN
-and
-.Dv LLONG_MAX
-are used to indicate underflow and overflow respectively.
+.Er ERANGE
+and the function return value is as follows:
+.Bl -column -offset indent "strtoimax" "overflow" "underflow"
+.It Sy Function Ta Sy overflow Ta Sy underflow
+.It Fn strtol Ta Dv LONG_MIN Ta Dv LONG_MAX
+.It Fn strtoll Ta Dv LLONG_MIN Ta Dv LLONG_MAX
+.It Fn strtoimax Ta Dv INTMAX_MIN Ta Dv INTMAX_MAX
+.It Fn strtoq Ta Dv LLONG_MIN Ta Dv LLONG_MAX
+.El
.Sh EXAMPLES
Ensuring that a string is a valid number (i.e., in range and containing no
trailing characters) requires clearing
@@ -233,9 +242,10 @@ The given string was out of range; the value converted has been clamped.
.Xr strtoul 3
.Sh STANDARDS
The
-.Fn strtol
+.Fn strtol ,
+.Fn strtoll ,
and
-.Fn strtoll
+.Fn strtoimax
functions conform to
.St -ansiC-99 .
The