Note that rmdir(1) is POSIX.2 compliant.

Include appropriate header files to bring prototypes into scope.
Use new error/warning display functions.
This commit is contained in:
jtc 1993-09-10 18:57:43 +00:00
parent 85a78a6bf6
commit a1c1508c9b
2 changed files with 18 additions and 13 deletions

View File

@ -33,7 +33,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" from: @(#)rmdir.1 6.5 (Berkeley) 6/27/91 .\" from: @(#)rmdir.1 6.5 (Berkeley) 6/27/91
.\" $Id: rmdir.1,v 1.6 1993/08/01 07:47:58 mycroft Exp $ .\" $Id: rmdir.1,v 1.7 1993/09/10 18:57:43 jtc Exp $
.\" .\"
.Dd June 27, 1991 .Dd June 27, 1991
.Dt RMDIR 1 .Dt RMDIR 1
@ -88,6 +88,5 @@ An error occurred.
.Sh STANDARDS .Sh STANDARDS
The The
.Nm rmdir .Nm rmdir
utility is expected to be utility conforms to
.St -p1003.2 .St -p1003.2-92 .
compatible.

View File

@ -39,7 +39,7 @@ char copyright[] =
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)rmdir.c 5.3 (Berkeley) 5/31/90";*/ /*static char sccsid[] = "from: @(#)rmdir.c 5.3 (Berkeley) 5/31/90";*/
static char rcsid[] = "$Id: rmdir.c,v 1.6 1993/08/01 18:58:47 mycroft Exp $"; static char rcsid[] = "$Id: rmdir.c,v 1.7 1993/09/10 18:57:44 jtc Exp $";
#endif /* not lint */ #endif /* not lint */
/* /*
@ -48,8 +48,14 @@ static char rcsid[] = "$Id: rmdir.c,v 1.6 1993/08/01 18:58:47 mycroft Exp $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <err.h>
static int rmdirp __P((char *));
static void usage __P((void));
int
main(argc, argv) main(argc, argv)
int argc; int argc;
char **argv; char **argv;
@ -58,7 +64,7 @@ main(argc, argv)
int ch; int ch;
int delete_parent_directories = 0; int delete_parent_directories = 0;
while ((ch = getopt (argc, argv, "p")) != EOF) { while ((ch = getopt (argc, argv, "p")) != -1) {
switch (ch) { switch (ch) {
case 'p': case 'p':
delete_parent_directories = 1; delete_parent_directories = 1;
@ -78,8 +84,7 @@ main(argc, argv)
for (errors = 0; *argv; argv++) { for (errors = 0; *argv; argv++) {
if (!delete_parent_directories) { if (!delete_parent_directories) {
if (rmdir(*argv) < 0) { if (rmdir(*argv) < 0) {
fprintf(stderr, "rmdir: %s: %s\n", warn ("%s", *argv);
*argv, strerror(errno));
errors = 1; errors = 1;
} }
} else { } else {
@ -92,8 +97,9 @@ main(argc, argv)
exit(errors); exit(errors);
} }
int static int
rmdirp (char *path) rmdirp (path)
char *path;
{ {
char *slash; char *slash;
@ -102,8 +108,7 @@ rmdirp (char *path)
while (slash != NULL) { while (slash != NULL) {
if (rmdir (path) < 0) { if (rmdir (path) < 0) {
fprintf(stderr, "rmdir: %s: %s\n", warn ("%s", path);
path, strerror(errno));
return -1; return -1;
} }
@ -116,13 +121,14 @@ rmdirp (char *path)
} }
if (rmdir (path) < 0) { if (rmdir (path) < 0) {
fprintf(stderr, "rmdir: %s: %s\n", path, strerror(errno)); warn ("%s", path);
return -1; return -1;
} }
return 0; return 0;
} }
static void
usage() usage()
{ {
fprintf(stderr, "usage: rmdir [-p] directory ...\n"); fprintf(stderr, "usage: rmdir [-p] directory ...\n");