X-Git-Url: http://dolda2000.com/gitweb/?p=utils.git;a=blobdiff_plain;f=nextep.c;h=151db938dc5eb52cf3df3274608c54a386460661;hp=0a8b6b64fefbff815e9ceea1cc94d9ba46aba3a5;hb=refs%2Fheads%2Fmaster;hpb=f2bcbba70451f991d8482afc13ba4c255f1e408a diff --git a/nextep.c b/nextep.c index 0a8b6b6..151db93 100644 --- a/nextep.c +++ b/nextep.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -15,6 +16,26 @@ static int ensuredir(char *base, char *dir) return(0); } +static void checkempty(char *dir) +{ + DIR *dh; + int empty; + struct dirent *de; + + if((dh = opendir(dir)) == NULL) + return; + empty = 1; + while((de = readdir(dh)) != NULL) { + if(de->d_name[0] != '.') { + empty = 0; + break; + } + } + closedir(dh); + if(empty) + rmdir(dir); +} + static void usage(FILE *out) { fprintf(out, "usage: nextep [-h] [-f FILE] [-s SET-VALUE] [DIR]\n"); @@ -81,6 +102,7 @@ int main(int argc, char **argv) fprintf(stderr, "nextep: %s: %s\n", fpath, strerror(errno)); exit(1); } + checkempty(base); } else { if(ensuredir(buf, base)) { fprintf(stderr, "nextep: %s: %s\n", base, strerror(errno));