applied Martin Kühl's inverse matching flag to stest
5ed5e90b
2 file(s) · +7 −4
| 67 | 67 | .B \-u |
|
| 68 | 68 | Test that files have their set-user-ID flag set. |
|
| 69 | 69 | .TP |
|
| 70 | + | .B \-v |
|
| 71 | + | Invert the sense of tests, only failing files pass. |
|
| 72 | + | .TP |
|
| 70 | 73 | .B \-w |
|
| 71 | 74 | Test that files are writable. |
|
| 72 | 75 | .TP |
| 22 | 22 | DIR *dir; |
|
| 23 | 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 | 26 | switch(opt) { |
|
| 27 | 27 | case 'n': /* newer than file */ |
|
| 28 | 28 | case 'o': /* older than file */ |
|
| 33 | 33 | FLAG(opt) = true; |
|
| 34 | 34 | break; |
|
| 35 | 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 | 37 | exit(2); |
|
| 38 | 38 | } |
|
| 39 | 39 | if(optind == argc) |
|
| 60 | 60 | test(const char *path, const char *name) { |
|
| 61 | 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 | 64 | && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ |
|
| 65 | 65 | && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ |
|
| 66 | 66 | && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */ |
|
| 75 | 75 | && (!FLAG('s') || st.st_size > 0) /* not empty */ |
|
| 76 | 76 | && (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */ |
|
| 77 | 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 | 79 | if(FLAG('q')) |
|
| 80 | 80 | exit(0); |
|
| 81 | 81 | match = true; |
|