1 /* rmdir.c - remove directory/path 2 * 3 * Copyright 2008 Rob Landley <rob@landley.net> 4 * 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/rmdir.html 6 7 USE_RMDIR(NEWTOY(rmdir, "<1(ignore-fail-on-non-empty)p(parents)", TOYFLAG_BIN)) 8 9 config RMDIR 10 bool "rmdir" 11 default y 12 help 13 usage: rmdir [-p] [DIR...] 14 15 Remove one or more directories. 16 17 -p Remove path 18 --ignore-fail-on-non-empty Ignore failures caused by non-empty directories 19 */ 20 21 #define FOR_rmdir 22 #include "toys.h" 23 do_rmdir(char * name)24static void do_rmdir(char *name) 25 { 26 char *temp; 27 28 do { 29 if (rmdir(name)) { 30 if (!FLAG(ignore_fail_on_non_empty) || errno != ENOTEMPTY) 31 perror_msg_raw(name); 32 return; 33 } 34 35 // Each -p cycle back up one slash, ignoring trailing and repeated /. 36 37 if (!toys.optflags) return; 38 do { 39 if (!(temp = strrchr(name, '/'))) return; 40 *temp = 0; 41 } while (!temp[1]); 42 } while (*name); 43 } 44 rmdir_main(void)45void rmdir_main(void) 46 { 47 char **s; 48 49 for (s=toys.optargs; *s; s++) do_rmdir(*s); 50 } 51