Add support for -k (checking sticky bit) to test(1)

This commit is contained in:
sin 2013-11-11 11:37:07 +00:00
parent 11c078d116
commit c23616555b
2 changed files with 7 additions and 2 deletions

3
test.1
View File

@ -29,6 +29,9 @@ ILE exists and is a regular file
.B \-g FILE
FILE exists and is set-group-ID
.TP
.B \-k FILE
FILE exists and its sticky bit is set
.TP
.B \-h FILE
FILE exists and is a symbolic link (same as -L)
.TP

6
test.c
View File

@ -57,7 +57,7 @@ unary(const char *op, const char *arg)
usage();
switch(op[1]) {
case 'b': case 'c': case 'd': case 'f': case 'g':
case 'p': case 'S': case 's': case 'u':
case 'k': case 'p': case 'S': case 's': case 'u':
if((r = stat(arg, &st)) == -1)
return false; /* -e */
switch(op[1]) {
@ -71,6 +71,8 @@ unary(const char *op, const char *arg)
return S_ISREG(st.st_mode);
case 'g':
return st.st_mode & S_ISGID;
case 'k':
return st.st_mode & S_ISVTX;
case 'p':
return S_ISFIFO(st.st_mode);
case 'S':
@ -153,5 +155,5 @@ usage(void)
const char *ket = (*argv0 == '[') ? " ]" : "";
eprintf("usage: %s string%s\n"
" %s [!] [-bcdefghLnprSstuwxz] string%s\n", argv0, ket, argv0, ket);
" %s [!] [-bcdefgkhLnprSstuwxz] string%s\n", argv0, ket, argv0, ket);
}