summaryrefslogtreecommitdiffstats
path: root/bin/test/test.c
diff options
context:
space:
mode:
authorse <se@FreeBSD.org>2000-07-10 21:29:28 +0000
committerse <se@FreeBSD.org>2000-07-10 21:29:28 +0000
commit2f863ef72b531599843632d285aeae102471f648 (patch)
treeb6a38d607f70ecc7e6226798455141a48b258247 /bin/test/test.c
parent7e67bebec575e247ec4fb4ff9bc23cfed52c1986 (diff)
downloadFreeBSD-src-2f863ef72b531599843632d285aeae102471f648.zip
FreeBSD-src-2f863ef72b531599843632d285aeae102471f648.tar.gz
Add support for 64bit integer comparisons.
Diffstat (limited to 'bin/test/test.c')
-rw-r--r--bin/test/test.c56
1 files changed, 50 insertions, 6 deletions
diff --git a/bin/test/test.c b/bin/test/test.c
index c9df4e3..73e6ebf 100644
--- a/bin/test/test.c
+++ b/bin/test/test.c
@@ -153,6 +153,8 @@ static int binop __P((void));
static int filstat __P((char *, enum token));
static int isoperand __P((void));
static int getn __P((const char *));
+static quad_t getq __P((const char *));
+static int intcmp __P((const char *, const char *));
static int newerf __P((const char *, const char *));
static int olderf __P((const char *, const char *));
static int equalf __P((const char *, const char *));
@@ -298,17 +300,17 @@ binop()
case STRGT:
return strcmp(opnd1, opnd2) > 0;
case INTEQ:
- return getn(opnd1) == getn(opnd2);
+ return intcmp(opnd1, opnd2) == 0;
case INTNE:
- return getn(opnd1) != getn(opnd2);
+ return intcmp(opnd1, opnd2) != 0;
case INTGE:
- return getn(opnd1) >= getn(opnd2);
+ return intcmp(opnd1, opnd2) >= 0;
case INTGT:
- return getn(opnd1) > getn(opnd2);
+ return intcmp(opnd1, opnd2) > 0;
case INTLE:
- return getn(opnd1) <= getn(opnd2);
+ return intcmp(opnd1, opnd2) <= 0;
case INTLT:
- return getn(opnd1) < getn(opnd2);
+ return intcmp(opnd1, opnd2) < 0;
case FILNT:
return newerf (opnd1, opnd2);
case FILOT:
@@ -443,6 +445,48 @@ getn(s)
return (int) r;
}
+/* atoi with error detection and 64 bit range */
+static quad_t
+getq(s)
+ const char *s;
+{
+ char *p;
+ quad_t r;
+
+ errno = 0;
+ r = strtoq(s, &p, 10);
+
+ if (errno != 0)
+ errx(2, "%s: out of range", s);
+
+ while (isspace((unsigned char)*p))
+ p++;
+
+ if (*p)
+ errx(2, "%s: bad number", s);
+
+ return r;
+}
+
+static int
+intcmp (s1, s2)
+ const char *s1, *s2;
+{
+ quad_t q1, q2;
+
+
+ q1 = getq(s1);
+ q2 = getq(s2);
+
+ if (q1 > q2)
+ return 1;
+
+ if (q1 < q2)
+ return -1;
+
+ return 0;
+}
+
static int
newerf (f1, f2)
const char *f1, *f2;
OpenPOWER on IntegriCloud