diff options
author | Anselm R Garbe <anselm@garbe.us> | 2013-08-13 19:15:04 +0200 |
---|---|---|
committer | Anselm R Garbe <anselm@garbe.us> | 2013-08-13 19:15:04 +0200 |
commit | 5ed5e90bfb7760f24661281cf7156087afbe49d3 (patch) | |
tree | 50914f6434067d272fffb6d449567a787aac5eac | |
parent | 13f787306f46a5f838987e3b546d85d1bb1c3c01 (diff) |
applied Martin Kühl's inverse matching flag to stest
-rw-r--r-- | stest.1 | 3 | ||||
-rw-r--r-- | stest.c | 8 |
2 files changed, 7 insertions, 4 deletions
@@ -67,6 +67,9 @@ Test that files are not empty. | |||
67 | .B \-u | 67 | .B \-u |
68 | Test that files have their set-user-ID flag set. | 68 | Test that files have their set-user-ID flag set. |
69 | .TP | 69 | .TP |
70 | .B \-v | ||
71 | Invert the sense of tests, only failing files pass. | ||
72 | .TP | ||
70 | .B \-w | 73 | .B \-w |
71 | Test that files are writable. | 74 | Test that files are writable. |
72 | .TP | 75 | .TP |
@@ -22,7 +22,7 @@ main(int argc, char *argv[]) { | |||
22 | DIR *dir; | 22 | DIR *dir; |
23 | int opt; | 23 | int opt; |
24 | 24 | ||
25 | while((opt = getopt(argc, argv, "abcdefghln:o:pqrsuwx")) != -1) | 25 | while((opt = getopt(argc, argv, "abcdefghln:o:pqrsuvwx")) != -1) |
26 | switch(opt) { | 26 | switch(opt) { |
27 | case 'n': /* newer than file */ | 27 | case 'n': /* newer than file */ |
28 | case 'o': /* older than file */ | 28 | case 'o': /* older than file */ |
@@ -33,7 +33,7 @@ main(int argc, char *argv[]) { | |||
33 | FLAG(opt) = true; | 33 | FLAG(opt) = true; |
34 | break; | 34 | break; |
35 | case '?': /* error: unknown flag */ | 35 | case '?': /* error: unknown flag */ |
36 | fprintf(stderr, "usage: %s [-abcdefghlpqrsuwx] [-n file] [-o file] [file...]\n", argv[0]); | 36 | fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] [-n file] [-o file] [file...]\n", argv[0]); |
37 | exit(2); | 37 | exit(2); |
38 | } | 38 | } |
39 | if(optind == argc) | 39 | if(optind == argc) |
@@ -60,7 +60,7 @@ void | |||
60 | test(const char *path, const char *name) { | 60 | test(const char *path, const char *name) { |
61 | struct stat st, ln; | 61 | struct stat st, ln; |
62 | 62 | ||
63 | if(!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */ | 63 | if((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */ |
64 | && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ | 64 | && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ |
65 | && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ | 65 | && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ |
66 | && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */ | 66 | && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */ |
@@ -75,7 +75,7 @@ test(const char *path, const char *name) { | |||
75 | && (!FLAG('s') || st.st_size > 0) /* not empty */ | 75 | && (!FLAG('s') || st.st_size > 0) /* not empty */ |
76 | && (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */ | 76 | && (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */ |
77 | && (!FLAG('w') || access(path, W_OK) == 0) /* writable */ | 77 | && (!FLAG('w') || access(path, W_OK) == 0) /* writable */ |
78 | && (!FLAG('x') || access(path, X_OK) == 0)) { /* executable */ | 78 | && (!FLAG('x') || access(path, X_OK) == 0)) != FLAG('v')) { /* executable */ |
79 | if(FLAG('q')) | 79 | if(FLAG('q')) |
80 | exit(0); | 80 | exit(0); |
81 | match = true; | 81 | match = true; |