Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdlib cleanups from (Kamil Rytarowski)
details: https://anonhg.NetBSD.org/src/rev/c0405de124de
branches: trunk
changeset: 335643:c0405de124de
user: christos <christos%NetBSD.org@localhost>
date: Sun Jan 18 18:01:41 2015 +0000
description:
cleanups from (Kamil Rytarowski)
diffstat:
lib/libc/stdlib/strtol.3 | 19 +++++++++++--------
lib/libc/stdlib/strtonum.c | 35 ++++++++++++++++-------------------
lib/libc/stdlib/strtoul.3 | 16 ++++++++--------
3 files changed, 35 insertions(+), 35 deletions(-)
diffs (181 lines):
diff -r 6fbd936509bc -r c0405de124de lib/libc/stdlib/strtol.3
--- a/lib/libc/stdlib/strtol.3 Sun Jan 18 17:59:36 2015 +0000
+++ b/lib/libc/stdlib/strtol.3 Sun Jan 18 18:01:41 2015 +0000
@@ -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 @@
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 @@
].
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 @@
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 -r 6fbd936509bc -r c0405de124de lib/libc/stdlib/strtonum.c
--- a/lib/libc/stdlib/strtonum.c Sun Jan 18 17:59:36 2015 +0000
+++ b/lib/libc/stdlib/strtonum.c Sun Jan 18 18:01:41 2015 +0000
@@ -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 @@
#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(ptr, NULL, 0, lo, hi, &e);
+ rv = strtoi(nptr, NULL, 0, minval, maxval, &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 -r 6fbd936509bc -r c0405de124de lib/libc/stdlib/strtoul.3
--- a/lib/libc/stdlib/strtoul.3 Sun Jan 18 17:59:36 2015 +0000
+++ b/lib/libc/stdlib/strtoul.3 Sun Jan 18 18:01:41 2015 +0000
@@ -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 @@
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 @@
].
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 @@
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,
Home |
Main Index |
Thread Index |
Old Index