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, "<1p", TOYFLAG_BIN)) 8 9 config RMDIR 10 bool "rmdir" 11 default y 12 help 13 usage: rmdir [-p] [dirname...] 14 15 Remove one or more directories. 16 17 -p Remove path 18 */ 19 20 #include "toys.h" 21 do_rmdir(char * name)22static void do_rmdir(char *name) 23 { 24 char *temp; 25 26 for (;;) { 27 if (rmdir(name)) { 28 perror_msg_raw(name); 29 return; 30 } 31 32 // Each -p cycle back up one slash, ignoring trailing and repeated /. 33 34 if (!toys.optflags) return; 35 do { 36 if (!(temp = strrchr(name, '/'))) return; 37 *temp = 0; 38 } while (!temp[1]); 39 } 40 } 41 rmdir_main(void)42void rmdir_main(void) 43 { 44 char **s; 45 46 for (s=toys.optargs; *s; s++) do_rmdir(*s); 47 } 48