commit a09638779e3235fc30e84a02e1a77b2319671b65 Author: Kamil CholewiƄski Date: Fri Oct 6 15:52:18 2017 +0200 [stest] is_hidden diff --git a/stest.c b/stest.c index 7a7b0bc..4da5230 100644 --- a/stest.c +++ b/stest.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -13,6 +14,7 @@ char *argv0; #define FLAG(x) (flag[(x)-'a']) +static int is_hidden(const char *path); static void test(const char *, const char *); static void usage(void); @@ -20,12 +22,25 @@ static int match = 0; static int flag[26]; static struct stat old, new; +static int +is_hidden(const char *path) +{ + char *basec, *bname; + int hidden; + + basec = strdup(path); + bname = basename(basec); + hidden = bname[0] == '.'; + free(basec); + return hidden; +} + static void test(const char *path, const char *name) { struct stat st, ln; - if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */ + if ((!stat(path, &st) && (FLAG('a') || !is_hidden(path)) /* hidden files */ && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */