From: Jim Meyering Date: Mon, 25 Mar 2002 09:53:07 +0000 (+0000) Subject: (age_of): Return -1 and 0 rather than 0 and 1. X-Git-Tag: FILEUTILS-4_1_8~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eae700da7d9b7384fd3feed5c40ad55ee30d9f4e;p=platform%2Fupstream%2Fcoreutils.git (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. --- 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], <) && age_of (argv[op + 1], &rt)) - return (TRUE == (lt > rt)); - else - return (FALSE); + le = age_of (argv[op - 1], <); + 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], <) && age_of (argv[op + 1], &rt)) - return (TRUE == (lt < rt)); - return (FALSE); + le = age_of (argv[op - 1], <); + re = age_of (argv[op + 1], &rt); + return le < re || (re == 0 && lt < rt); } break; }