ScrapExplorer - rmdir.c

Home / usr / light_builtins Lines: 3 | Size: 1403 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* Light builtins's (C version) 2 * rmdir - remove empty directories 3 * A lightweight repository of useful shell commands 4 * GitHub: https://www.github.com/0x4248/light_builtins 5 * Licence: GNU General Public License v3.0 6 * By: 0x4248 7 */ 8 9#include <dirent.h> 10#include <stdio.h> 11#include <stdlib.h> 12#include <string.h> 13#include <sys/stat.h> 14#include <sys/types.h> 15#include <unistd.h> 16 17#include "config.h" 18 19int main(int argc, char *argv[]) { 20 if (argc >= 2 && 21 (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { 22 printf("Light Builtins (C) %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, 23 VERSION_PATCH, EXTRA_VERSION); 24 return 0; 25 } 26 int i; 27 for (i = 1; i < argc; i++) { 28 DIR *dir = opendir(argv[i]); 29 if (dir) { 30 struct dirent *ent; 31 while ((ent = readdir(dir)) != NULL) { 32 if (strcmp(ent->d_name, ".") != 0 && 33 strcmp(ent->d_name, "..") != 0) { 34 printf("Directory is not empty\n"); 35 return 1; 36 } 37 } 38 closedir(dir); 39 } else { 40 perror("Cannot open directory"); 41 return 1; 42 } 43 if (rmdir(argv[i]) == -1) { 44 perror("Cannot remove directory"); 45 return 1; 46 } 47 } 48 return 0; 49}
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.