aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stest.13
-rw-r--r--stest.c8
2 files changed, 7 insertions, 4 deletions
diff --git a/stest.1 b/stest.1
index bb48f45..2667d8a 100644
--- a/stest.1
+++ b/stest.1
@@ -67,6 +67,9 @@ Test that files are not empty.
67.B \-u 67.B \-u
68Test that files have their set-user-ID flag set. 68Test that files have their set-user-ID flag set.
69.TP 69.TP
70.B \-v
71Invert the sense of tests, only failing files pass.
72.TP
70.B \-w 73.B \-w
71Test that files are writable. 74Test that files are writable.
72.TP 75.TP
diff --git a/stest.c b/stest.c
index e1dcf36..8fac42a 100644
--- a/stest.c
+++ b/stest.c
@@ -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
60test(const char *path, const char *name) { 60test(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;