Skip to content

Commit 5ed5e90

Browse files
committed
applied Martin Kühl's inverse matching flag to stest
1 parent 13f7873 commit 5ed5e90

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

stest.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Test that files are not empty.
6767
.B \-u
6868
Test that files have their set-user-ID flag set.
6969
.TP
70+
.B \-v
71+
Invert the sense of tests, only failing files pass.
72+
.TP
7073
.B \-w
7174
Test that files are writable.
7275
.TP

stest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ main(int argc, char *argv[]) {
2222
DIR *dir;
2323
int opt;
2424

25-
while((opt = getopt(argc, argv, "abcdefghln:o:pqrsuwx")) != -1)
25+
while((opt = getopt(argc, argv, "abcdefghln:o:pqrsuvwx")) != -1)
2626
switch(opt) {
2727
case 'n': /* newer than file */
2828
case 'o': /* older than file */
@@ -33,7 +33,7 @@ main(int argc, char *argv[]) {
3333
FLAG(opt) = true;
3434
break;
3535
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]);
3737
exit(2);
3838
}
3939
if(optind == argc)
@@ -60,7 +60,7 @@ void
6060
test(const char *path, const char *name) {
6161
struct stat st, ln;
6262

63-
if(!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */
63+
if((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */
6464
&& (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */
6565
&& (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */
6666
&& (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */
@@ -75,7 +75,7 @@ test(const char *path, const char *name) {
7575
&& (!FLAG('s') || st.st_size > 0) /* not empty */
7676
&& (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */
7777
&& (!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 */
7979
if(FLAG('q'))
8080
exit(0);
8181
match = true;

0 commit comments

Comments
 (0)