ash: make test/expr support 'file1 -ot file2'

This commit is contained in:
Ben Gras 2010-07-03 22:18:11 +00:00
parent 4d3c887d6b
commit 01fcee7d71
2 changed files with 7 additions and 1 deletions

View file

@ -11,6 +11,7 @@ AND2 & 2
STREQ = 4 OP_STRING STREQ = 4 OP_STRING
STRNE != 4 OP_STRING STRNE != 4 OP_STRING
NEWER -newer 4 OP_STRING NEWER -newer 4 OP_STRING
OLDER -ot 4 OP_STRING
EQ -eq 4 OP_INT EQ -eq 4 OP_INT
NE -ne 4 OP_INT NE -ne 4 OP_INT
GT -gt 4 OP_INT GT -gt 4 OP_INT

View file

@ -347,13 +347,18 @@ filebit:
sp->u.num = fs->rcode >= 0? fs->stat.st_size : 0L; sp->u.num = fs->rcode >= 0? fs->stat.st_size : 0L;
sp->type = INTEGER; sp->type = INTEGER;
break; break;
case OLDER:
case NEWER: case NEWER:
if (stat(sp->u.string, &st1) != 0) { if (stat(sp->u.string, &st1) != 0) {
sp->u.num = 0; sp->u.num = 0;
} else if (stat((sp + 1)->u.string, &st2) != 0) { } else if (stat((sp + 1)->u.string, &st2) != 0) {
sp->u.num = 1; sp->u.num = 1;
} else { } else {
sp->u.num = st1.st_mtime >= st2.st_mtime; int isnewer = st1.st_mtime >= st2.st_mtime;
if(op == NEWER)
sp->u.num = isnewer;
else
sp->u.num = !isnewer;
} }
sp->type = INTEGER; sp->type = INTEGER;
break; break;