1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1992-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
20 ***********************************************************************/
29 static const char usage
[] =
30 "[-?\n@(#)$Id: rmdir (AT&T Research) 2006-08-24 $\n]"
32 "[+NAME?rmdir - remove empty directories]"
33 "[+DESCRIPTION?\brmdir\b deletes each given directory. The directory "
34 "must be empty; containing no entries other than \b.\b or \b..\b. "
35 "If a directory and a subdirectory of that directory are specified "
36 "as operands, the subdirectory must be specified before the parent "
37 "so that the parent directory will be empty when \brmdir\b attempts "
39 "[e:ignore-fail-on-non-empty?Ignore each non-empty directory failure.]"
40 "[p:parents?Remove each explicit \adirectory\a argument directory that "
41 "becomes empty after its child directories are removed.]"
42 "[s:suppress?Suppress the message printed on the standard error when "
43 "\b-p\b is in effect.]"
48 "[+0?All directories deleted successfully.]"
49 "[+>0?One or more directories could not be deleted.]"
51 "[+SEE ALSO?\bmkdir\b(1), \brm\b(1), \brmdir\b(2), \bunlink\b(2)]"
57 b_rmdir(int argc
, char** argv
, void* context
)
66 cmdinit(argc
, argv
, context
, ERROR_CATALOG
, 0);
67 while (n
= optget(argv
, usage
)) switch (n
)
79 error(2, "%s", opt_info
.arg
);
82 error(ERROR_usage(2), "%s", opt_info
.arg
);
85 argv
+= opt_info
.index
;
86 if (error_info
.errors
|| !*argv
)
87 error(ERROR_usage(2), "%s", optusage(NiL
));
93 if (pflag
) end
+= strlen(dir
);
99 if (!eflag
|| errno
!= EEXIST
101 && errno
!= ENOTEMPTY
108 error(ERROR_system(0), "%s: cannot remove", dir
);
114 do if (end
<= dir
) goto next
; while (*--end
!= '/');
115 do if (end
<= dir
) goto next
; while (*(end
- 1) == '/' && end
--);
120 return(error_info
.errors
!= 0);