summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-06-29 00:20:12 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-06-29 00:20:12 +0000
commit44c477eb5293a32c2d0296533d89dc9bfa704de4 (patch)
treec4e058cb87646c64915f3a7251045eaecabe6d91 /lib
parent88005fb8454df5ee45b68e33cb8bccfd47018a93 (diff)
Replace strtou?q() with the more standard strtou?ll(), using weak
aliases to fake up strtou?q(). espie@ OK.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/Makefile.inc8
-rw-r--r--lib/libc/stdlib/strtol.327
-rw-r--r--lib/libc/stdlib/strtoll.c (renamed from lib/libc/stdlib/strtoq.c)44
-rw-r--r--lib/libc/stdlib/strtoul.329
-rw-r--r--lib/libc/stdlib/strtoull.c (renamed from lib/libc/stdlib/strtouq.c)42
5 files changed, 108 insertions, 42 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 55fb00fcf4b..4b4c88b9af5 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -6,8 +6,8 @@
SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c bsearch.c calloc.c \
cfree.c exit.c getenv.c getopt.c getsubopt.c heapsort.c l64a.c \
malloc.c merge.c multibyte.c putenv.c qsort.c radixsort.c rand.c \
- random.c realpath.c setenv.c strtod.c strtol.c strtoq.c strtoul.c \
- strtouq.c system.c tfind.c tsearch.c \
+ random.c realpath.c setenv.c strtod.c strtol.c strtoll.c strtoul.c \
+ strtoull.c system.c tfind.c tsearch.c \
_rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \
mrand48.c nrand48.c seed48.c srand48.c qabs.c qdiv.c
@@ -48,8 +48,8 @@ MLINKS+=random.3 srandom.3 random.3 srandomdev.3
MLINKS+=rand48.3 drand48.3 rand48.3 erand48.3 rand48.3 lrand48.3
MLINKS+=rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 jrand48.3
MLINKS+=rand48.3 srand48.3 rand48.3 seed48.3 rand48.3 lcong48.3
-MLINKS+=strtol.3 strtoq.3
-MLINKS+=strtoul.3 strtouq.3
+MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3
+MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3
MLINKS+=tsearch.3 tfind.3
MLINKS+=tsearch.3 tdelete.3
MLINKS+=tsearch.3 twalk.3
diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3
index afdb84f19b8..a5bdff0b81b 100644
--- a/lib/libc/stdlib/strtol.3
+++ b/lib/libc/stdlib/strtol.3
@@ -33,21 +33,27 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: strtol.3,v 1.9 2000/08/09 15:51:21 aaron Exp $
+.\" $OpenBSD: strtol.3,v 1.10 2002/06/29 00:20:11 millert Exp $
.\"
.Dd June 25, 1992
.Dt STRTOL 3
.Os
.Sh NAME
.Nm strtol ,
+.Nm strtoll ,
.Nm strtoq
-.Nd convert string value to a long or quad_t integer
+.Nd convert string value to a long or long long 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 <sys/types.h>
.Fd #include <stdlib.h>
.Fd #include <limits.h>
@@ -62,12 +68,17 @@ to a
.Li long
value.
The
-.Fn strtoq
+.Fn strtoll
function converts the string in
.Fa nptr
to a
-.Li quad_t
+.Li long long
value.
+The
+.Fn strtoq
+function is a deprecated equivalent of
+.Fn strtoll
+and is provided for backwards compatibility with legacy programs.
The conversion is done according to the given
.Fa base ,
which must be a number between 2 and 36 inclusive or the special value 0.
@@ -141,6 +152,14 @@ In both cases,
.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.
.Sh EXAMPLES
Ensuring that a string is a valid number (i.e., in range and containing no
trailing characters) requires clearing
diff --git a/lib/libc/stdlib/strtoq.c b/lib/libc/stdlib/strtoll.c
index 44aabd73f0a..b0eb6d198c7 100644
--- a/lib/libc/stdlib/strtoq.c
+++ b/lib/libc/stdlib/strtoll.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: strtoq.c,v 1.4 1996/08/19 08:33:52 tholo Exp $";
+static const char rcsid[] = "$OpenBSD: strtoll.c,v 1.1 2002/06/29 00:20:11 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -43,21 +43,21 @@ static char rcsid[] = "$OpenBSD: strtoq.c,v 1.4 1996/08/19 08:33:52 tholo Exp $"
#include <stdlib.h>
/*
- * Convert a string to a quad integer.
+ * Convert a string to a long long.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
-quad_t
-strtoq(nptr, endptr, base)
+long long
+strtoll(nptr, endptr, base)
const char *nptr;
char **endptr;
- register int base;
+ int base;
{
- register const char *s;
- register quad_t acc, cutoff;
- register int c;
- register int neg, any, cutlim;
+ const char *s;
+ long long acc, cutoff;
+ int c;
+ int neg, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
@@ -92,7 +92,7 @@ strtoq(nptr, endptr, base)
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
- * digit. For instance, if the range for quads is
+ * digit. For instance, if the range for long longs is
* [-9223372036854775808..9223372036854775807] and the input base
* is 10, cutoff will be set to 922337203685477580 and cutlim to
* either 7 (neg==0) or 8 (neg==1), meaning that if we have
@@ -103,7 +103,7 @@ strtoq(nptr, endptr, base)
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
- cutoff = neg ? QUAD_MIN : QUAD_MAX;
+ cutoff = neg ? LLONG_MIN : LLONG_MAX;
cutlim = cutoff % base;
cutoff /= base;
if (neg) {
@@ -125,9 +125,9 @@ strtoq(nptr, endptr, base)
if (any < 0)
continue;
if (neg) {
- if (acc < cutoff || acc == cutoff && c > cutlim) {
+ if (acc < cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- acc = QUAD_MIN;
+ acc = LLONG_MIN;
errno = ERANGE;
} else {
any = 1;
@@ -135,9 +135,9 @@ strtoq(nptr, endptr, base)
acc -= c;
}
} else {
- if (acc > cutoff || acc == cutoff && c > cutlim) {
+ if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- acc = QUAD_MAX;
+ acc = LLONG_MAX;
errno = ERANGE;
} else {
any = 1;
@@ -150,3 +150,17 @@ strtoq(nptr, endptr, base)
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+
+#ifdef __weak_alias
+__weak_alias(strtoq, strtoll);
+#else
+quad_t
+strtoq(nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ int base;
+{
+
+ return ((quad_t)strtoll(nptr, endptr, base);
+}
+#endif
diff --git a/lib/libc/stdlib/strtoul.3 b/lib/libc/stdlib/strtoul.3
index 61269bc900f..6d55de4d7a9 100644
--- a/lib/libc/stdlib/strtoul.3
+++ b/lib/libc/stdlib/strtoul.3
@@ -33,21 +33,27 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: strtoul.3,v 1.9 2002/04/30 16:31:42 mpech Exp $
+.\" $OpenBSD: strtoul.3,v 1.10 2002/06/29 00:20:11 millert Exp $
.\"
.Dd June 25, 1992
.Dt STRTOUL 3
.Os
.Sh NAME
.Nm strtoul ,
+.Nm strtoull ,
.Nm strtouq
-.Nd convert a string to an unsigned long or uquad_t integer
+.Nd convert a string to an unsigned long or unsigned long long integer
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Fd #include <limits.h>
.Ft unsigned long
.Fn strtoul "const char *nptr" "char **endptr" "int base"
.Pp
+.Fd #include <stdlib.h>
+.Fd #include <limits.h>
+.Ft unsigned long long
+.Fn strtoull "const char *nptr" "char **endptr" "int base"
+.Pp
.Fd #include <sys/types.h>
.Fd #include <stdlib.h>
.Fd #include <limits.h>
@@ -62,12 +68,17 @@ to an
.Li unsigned long
value.
The
-.Fn strtouq
+.Fn strtoull
function converts the string in
.Fa nptr
-to a
-.Li u_quad_t
+to an
+.Li unsigned long long
value.
+The
+.Fn strtouq
+function is a deprecated equivalent of
+.Fn strtoull
+and is provided for backwards compatibility with legacy programs.
The conversion is done according to the given
.Fa base ,
which must be a number between 2 and 36 inclusive
@@ -148,6 +159,14 @@ and sets the global variable
to
.Er ERANGE .
.Pp
+The
+.Fn strtoull
+function has identical return values except that
+.Dv ULLONG_MIN
+and
+.Dv ULLONG_MAX
+are used to indicate underflow and overflow respectively.
+.Pp
There is no way to determine if
.Fn strtoul
has processed a negative number (and returned an unsigned value) short of
diff --git a/lib/libc/stdlib/strtouq.c b/lib/libc/stdlib/strtoull.c
index 1f29a22f33d..7b4dd56c01b 100644
--- a/lib/libc/stdlib/strtouq.c
+++ b/lib/libc/stdlib/strtoull.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: strtouq.c,v 1.4 1996/08/19 08:33:53 tholo Exp $";
+static const char rcsid[] = "$OpenBSD: strtoull.c,v 1.1 2002/06/29 00:20:11 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -43,21 +43,21 @@ static char rcsid[] = "$OpenBSD: strtouq.c,v 1.4 1996/08/19 08:33:53 tholo Exp $
#include <stdlib.h>
/*
- * Convert a string to an unsigned quad integer.
+ * Convert a string to an unsigned long long.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
-u_quad_t
-strtouq(nptr, endptr, base)
+unsigned long long
+strtoull(nptr, endptr, base)
const char *nptr;
char **endptr;
- register int base;
+ int base;
{
- register const char *s;
- register u_quad_t acc, cutoff;
- register int c;
- register int neg, any, cutlim;
+ const char *s;
+ unsigned long long acc, cutoff;
+ int c;
+ int neg, any, cutlim;
/*
* See strtoq for comments as to the logic used.
@@ -83,8 +83,8 @@ strtouq(nptr, endptr, base)
if (base == 0)
base = c == '0' ? 8 : 10;
- cutoff = UQUAD_MAX / (u_quad_t)base;
- cutlim = UQUAD_MAX % (u_quad_t)base;
+ cutoff = ULLONG_MAX / (unsigned long long)base;
+ cutlim = ULLONG_MAX % (unsigned long long)base;
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
if (isdigit(c))
c -= '0';
@@ -96,13 +96,13 @@ strtouq(nptr, endptr, base)
break;
if (any < 0)
continue;
- if (acc > cutoff || acc == cutoff && c > cutlim) {
+ if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
- acc = UQUAD_MAX;
+ acc = ULLONG_MAX;
errno = ERANGE;
} else {
any = 1;
- acc *= (u_quad_t)base;
+ acc *= (unsigned long long)base;
acc += c;
}
}
@@ -112,3 +112,17 @@ strtouq(nptr, endptr, base)
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
+
+#ifdef __weak_alias
+__weak_alias(strtouq, strtoull);
+#else
+u_quad_t
+strtouq(nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ int base;
+{
+
+ return ((u_quad_t)strtoull(nptr, endptr, base);
+}
+#endif