/* "isdirempty" -- checks whether the given directory * (only one) is empty or not. Returns 0 if empty, * !=0 otherwise or in case of an error. * * (w) and (c) Mar 2000 by J.Tevessen */ #include #include #include #include int main (int argc, char** argv) { int ret = EXIT_FAILURE; if (2 == argc) { DIR* dir = opendir (argv[1]); if (NULL != dir) { if (NULL != readdir (dir)) { /* skip "." */ if (NULL != readdir (dir)) { /* skip ".." */ if (NULL == readdir (dir)) ret = EXIT_SUCCESS; } } if (0 != closedir (dir)) perror ("closedir()"); } else perror (argv[1]); } else fputs ("Bad arguments.\n", stderr); return ret; }