summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2015-01-18 18:01:41 +0000
committerchristos <christos@NetBSD.org>2015-01-18 18:01:41 +0000
commitc86e76fd2ca515b33c4c90c14c64e3f652e3d5bd (patch)
tree70131f789a0702b368132fa888d4d43e73866b3b /lib/libc/stdlib
parentd010fbe8c51c709f93aabf068f393ae1bb7bcb13 (diff)
cleanups from (Kamil Rytarowski)
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/strtol.319
-rw-r--r--lib/libc/stdlib/strtonum.c35
-rw-r--r--lib/libc/stdlib/strtoul.316
3 files changed, 35 insertions, 35 deletions
diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3
index e04cab0d7fc..5eb586bea6a 100644
--- a/lib/libc/stdlib/strtol.3
+++ b/lib/libc/stdlib/strtol.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: strtol.3,v 1.28 2015/01/16 23:46:37 wiz Exp $
+.\" $NetBSD: strtol.3,v 1.29 2015/01/18 18:01:41 christos Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -55,7 +55,7 @@
.Pp
.In inttypes.h
.Ft intmax_t
-.Fn strtoi "const char * restrict nptr" "char ** restrict endptr" "int base" "intmax_t lo" "intmax_t hi" "int *rerror"
+.Fn strtoi "const char * restrict nptr" "char ** restrict endptr" "int base" "intmax_t lo" "intmax_t hi" "int *rstatus"
.Ft intmax_t
.Fn strtoimax "const char * restrict nptr" "char ** restrict endptr" "int base"
.Pp
@@ -92,7 +92,7 @@ value.
The
.Fn strtoi
function
-is using internally
+uses internally
.Fn strtoimax
and ensures that the result is always in the range [
.Fa lo ..
@@ -100,16 +100,19 @@ and ensures that the result is always in the range [
].
In adddition it always places
.Dv 0
-on success or an error value in the
-.Fa rerror
+on success or a conversion status in the
+.Fa rstatus
argument, avoiding the
.Dv errno
gymnastics the other functions require.
The
-.Fa rerror
+.Fn strtoi
+function doesn't affect errno on exit.
+The
+.Fa rstatus
argument can be
.Dv NULL
-if errors are to be ignored.
+if conversion status is to be ignored.
The
.Fn strtoq
function
@@ -323,7 +326,7 @@ In addition to the above errors
returns:
.Bl -tag -width Er
.It Bq Er ECANCELED
-The string did not contain any characters that could be converted.
+The string did not contain any characters that were converted.
.It Bq Er ENOTSUP
The string contained non-numeric characters that did not get converted.
In this case,
diff --git a/lib/libc/stdlib/strtonum.c b/lib/libc/stdlib/strtonum.c
index 235c4fe962e..ad2eabf93ab 100644
--- a/lib/libc/stdlib/strtonum.c
+++ b/lib/libc/stdlib/strtonum.c
@@ -1,4 +1,4 @@
-/* $NetBSD: strtonum.c,v 1.1 2015/01/16 18:41:33 christos Exp $ */
+/* $NetBSD: strtonum.c,v 1.2 2015/01/18 18:01:41 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: strtonum.c,v 1.1 2015/01/16 18:41:33 christos Exp $");
+__RCSID("$NetBSD: strtonum.c,v 1.2 2015/01/18 18:01:41 christos Exp $");
#define _OPENBSD_SOURCE
#include <stdio.h>
@@ -37,31 +37,28 @@ __RCSID("$NetBSD: strtonum.c,v 1.1 2015/01/16 18:41:33 christos Exp $");
#include <errno.h>
#include <inttypes.h>
-/*
- * Problems with the strtonum(3) API:
- * - will return 0 on failure; 0 might not be in range, so
- * that necessitates an error check even if you want to avoid it.
- * - does not differentiate 'illegal' returns, so we can't tell
- * the difference between partial and no conversions.
- * - returns english strings
- * - can't set the base, or find where the conversion ended
- */
long long
-strtonum(const char * __restrict ptr, long long lo, long long hi,
- const char ** __restrict res)
+strtonum(const char *nptr, long long minval, long long maxval,
+ const char **errstr)
{
int e;
- intmax_t rv;
+ long long rv;
const char *resp;
- if (res == NULL)
- res = &resp;
+ if (errstr == NULL)
+ errstr = &resp;
+
+ rv = strtoi(nptr, NULL, 0, minval, maxval, &e);
- rv = strtoi(ptr, NULL, 0, lo, hi, &e);
if (e == 0) {
- *res = NULL;
+ *errstr = NULL;
return rv;
}
- *res = e != ERANGE ? "invalid" : (rv == hi ? "too large" : "too small");
+
+ if (e == ERANGE)
+ *errstr = (rv == maxval ? "too large" : "too small");
+ else
+ *errstr = "invalid";
+
return 0;
}
diff --git a/lib/libc/stdlib/strtoul.3 b/lib/libc/stdlib/strtoul.3
index 444a7468e33..ee0ebdebe55 100644
--- a/lib/libc/stdlib/strtoul.3
+++ b/lib/libc/stdlib/strtoul.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: strtoul.3,v 1.27 2015/01/16 23:46:37 wiz Exp $
+.\" $NetBSD: strtoul.3,v 1.28 2015/01/18 18:01:41 christos Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -55,7 +55,7 @@
.Pp
.In inttypes.h
.Ft uintmax_t
-.Fn strtou "const char * restrict nptr" "char ** restrict endptr" "int base" "uintmax_t lo" "uintmax_t hi" "int *rerror"
+.Fn strtou "const char * restrict nptr" "char ** restrict endptr" "int base" "uintmax_t lo" "uintmax_t hi" "int *rstatus"
.Ft uintmax_t
.Fn strtoumax "const char * restrict nptr" "char ** restrict endptr" "int base"
.Pp
@@ -91,7 +91,7 @@ to an
value.
.Fn strtou
function
-is using internally
+uses internally
.Fn strtoumax
and ensures that the result is always in the range [
.Fa lo ..
@@ -99,16 +99,16 @@ and ensures that the result is always in the range [
].
In adddition it always places
.Dv 0
-on success or an error value in the
-.Fa rerror
+on success or a conversion status in the
+.Fa rstatus
argument, avoiding the
.Dv errno
gymnastics the other functions require.
The
-.Fa rerror
+.Fa rstatus
argument can be
.Dv NULL
-if errors are to be ignored.
+if conversion status is to be ignored.
The
.Fn strtouq
function
@@ -296,7 +296,7 @@ In addition to the above errors
returns:
.Bl -tag -width Er
.It Bq Er ECANCELED
-The string did not contain any characters that could be converted.
+The string did not contain any characters that were converted.
.It Bq Er ENOTSUP
The string contained non-numeric characters that did not get converted.
In this case,