[hackers] [sbase] test: more efficient -e flag || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Mon, 14 May 2012 14:33:27 +0200 (CEST)

changeset: 116:1a132443ba6c
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Mon May 14 13:33:07 2012 +0100
files: test.c
description:
test: more efficient -e flag


diff -r 1297361049c3 -r 1a132443ba6c test.c
--- a/test.c Sat May 12 18:01:27 2012 +0100
+++ b/test.c Mon May 14 13:33:07 2012 +0100
_AT_@ -58,8 +58,8 @@
         if(op[0] != '-' || op[1] == '\0' || op[2] != '\0')
                 usage();
         switch(op[1]) {
- case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'p': case 'S': case 's': case 'u':
+ case 'b': case 'c': case 'd': case 'f': case 'g':
+ case 'p': case 'S': case 's': case 'u':
                 if((r = stat(arg, &st)) == -1)
                         return false; /* -e */
                 switch(op[1]) {
_AT_@ -69,8 +69,6 @@
                         return S_ISCHR(st.st_mode);
                 case 'd':
                         return S_ISDIR(st.st_mode);
- case 'e':
- return true;
                 case 'f':
                         return S_ISREG(st.st_mode);
                 case 'g':
_AT_@ -84,18 +82,20 @@
                 case 'u':
                         return st.st_mode & S_ISUID;
                 }
- case 'h': case 'L':
- return lstat(arg, &st) == 0 && S_ISLNK(st.st_mode);
- case 'n':
- return arg[0] != '\0';
- case 't':
- return isatty((int)estrtol(arg, 0));
+ case 'e':
+ return access(arg, F_OK) == 0;
         case 'r':
                 return access(arg, R_OK) == 0;
         case 'w':
                 return access(arg, W_OK) == 0;
         case 'x':
                 return access(arg, X_OK) == 0;
+ case 'h': case 'L':
+ return lstat(arg, &st) == 0 && S_ISLNK(st.st_mode);
+ case 't':
+ return isatty((int)estrtol(arg, 0));
+ case 'n':
+ return arg[0] != '\0';
         case 'z':
                 return arg[0] == '\0';
         default:
Received on Mon May 14 2012 - 14:33:27 CEST

This archive was generated by hypermail 2.3.0 : Mon May 14 2012 - 14:36:05 CEST