summaryrefslogtreecommitdiff
path: root/src/test.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-03-25 09:53:07 +0000
committerJim Meyering <jim@meyering.net>2002-03-25 09:53:07 +0000
commiteae700da7d9b7384fd3feed5c40ad55ee30d9f4e (patch)
tree9075ad8bf9acad81a21d666a3b5cc96c1c9d2861 /src/test.c
parentdc3bf580fcfee27444f9d0f2e58ad72be9ba9a1d (diff)
downloadcoreutils-eae700da7d9b7384fd3feed5c40ad55ee30d9f4e.tar.xz
(age_of): Return -1 and 0 rather than 0 and 1.
Might as well keep it simple, and like bash. (binary_operator): Fix bug with -nt and -ot, when one of the files did not exist. We want to be compatible with the ksh93 documentation, and with Bash.
Diffstat (limited to 'src/test.c')
-rw-r--r--src/test.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/test.c b/src/test.c
index 79f65d814..33ae18174 100644
--- a/src/test.c
+++ b/src/test.c
@@ -293,19 +293,15 @@ isint (register char *string, intmax_t *result)
}
/* Find the modification time of FILE, and stuff it into *AGE.
- Return nonzero if successful, else zero. */
+ Return 0 if successful, -1 if not. */
static int
age_of (char *filename, time_t *age)
{
struct stat finfo;
-
- if (test_stat (filename, &finfo) < 0)
- return (0);
-
- if (age)
+ int r = test_stat (filename, &finfo);
+ if (r == 0)
*age = finfo.st_mtime;
-
- return (1);
+ return r;
}
/*
@@ -520,13 +516,13 @@ binary_operator (void)
{
/* nt - newer than */
time_t lt, rt;
+ int le, re;
pos += 3;
if (l_is_l || r_is_l)
test_syntax_error (_("-nt does not accept -l\n"), NULL);
- if (age_of (argv[op - 1], &lt) && age_of (argv[op + 1], &rt))
- return (TRUE == (lt > rt));
- else
- return (FALSE);
+ le = age_of (argv[op - 1], &lt);
+ re = age_of (argv[op + 1], &rt);
+ return le > re || (le == 0 && lt > rt);
}
if (argv[op][2] == 'e' && !argv[op][3])
@@ -594,12 +590,13 @@ binary_operator (void)
{
/* ot - older than */
time_t lt, rt;
+ int le, re;
pos += 3;
if (l_is_l || r_is_l)
test_syntax_error (_("-ot does not accept -l\n"), NULL);
- if (age_of (argv[op - 1], &lt) && age_of (argv[op + 1], &rt))
- return (TRUE == (lt < rt));
- return (FALSE);
+ le = age_of (argv[op - 1], &lt);
+ re = age_of (argv[op + 1], &rt);
+ return le < re || (re == 0 && lt < rt);
}
break;
}