Make POSIX 1003.2 (D11.2) compliant.
Update manpage to use new -mandoc macros.
This commit is contained in:
parent
3c0990e964
commit
ce9521b022
|
@ -34,9 +34,6 @@
|
|||
.\"
|
||||
.\" @(#)rmdir.1 6.5 (Berkeley) 6/27/91
|
||||
.\"
|
||||
.\" $Header: /cvsroot/src/bin/rmdir/rmdir.1,v 1.3 1993/03/23 00:27:22 cgd Exp $
|
||||
.\"
|
||||
.Vx
|
||||
.Dd June 27, 1991
|
||||
.Dt RMDIR 1
|
||||
.Os
|
||||
|
@ -60,33 +57,36 @@ must be specified first so the parent directory
|
|||
is empty when
|
||||
.Nm rmdir
|
||||
tries to remove it.
|
||||
.\" .Pp
|
||||
.\" The following option is available:
|
||||
.\" .Tw Ds
|
||||
.\" .Tp Fl p
|
||||
.\" Each
|
||||
.\" .Ar directory
|
||||
.\" argument is treated as a pathname of which all
|
||||
.\" components will be removed, if they are empty,
|
||||
.\" starting with the last most component.
|
||||
.\" (See
|
||||
.\" .Xr rm 1
|
||||
.\" for fully non-discriminant recursive removal).
|
||||
.Pp
|
||||
The following option is available:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl p
|
||||
Each
|
||||
.Ar directory
|
||||
argument is treated as a pathname of which all
|
||||
components will be removed, if they are empty,
|
||||
starting with the last most component.
|
||||
(See
|
||||
.Xr rm 1
|
||||
for fully non-discriminant recursive removal).
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Nm rmdir
|
||||
utility exits with one of the following values:
|
||||
.Tw Ds
|
||||
.Tp Li \&0
|
||||
.Bl -tag -width Ds
|
||||
.It Li \&0
|
||||
Each directory entry specified by a dir operand
|
||||
referred to an empty directory and was removed
|
||||
successfully.
|
||||
.Tp Li \&>\&0
|
||||
.It Li \&>\&0
|
||||
An error occurred.
|
||||
.Tp
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr rm 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm rmdir
|
||||
function is expected to be POSIX 1003.2 compatible.
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compatible.
|
||||
|
|
|
@ -39,29 +39,91 @@ char copyright[] =
|
|||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)rmdir.c 5.3 (Berkeley) 5/31/90";
|
||||
static char rcsid[] = "$Header: /cvsroot/src/bin/rmdir/rmdir.c,v 1.3 1993/03/23 00:27:24 cgd Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Remove directory
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int errors;
|
||||
int ch;
|
||||
int delete_parent_directories = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: rmdir directory ...\n");
|
||||
exit(1);
|
||||
}
|
||||
for (errors = 0; *++argv;)
|
||||
if (rmdir(*argv) < 0) {
|
||||
fprintf(stderr, "rmdir: ");
|
||||
perror(*argv);
|
||||
errors = 1;
|
||||
while ((ch = getopt (argc, argv, "p")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'p':
|
||||
delete_parent_directories = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
if (!*(argv += optind)) {
|
||||
usage ();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
for (errors = 0; *argv; argv++) {
|
||||
if (!delete_parent_directories) {
|
||||
if (rmdir(*argv) < 0) {
|
||||
fprintf(stderr, "rmdir: %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
errors = 1;
|
||||
}
|
||||
} else {
|
||||
if (rmdirp(*argv) < 0) {
|
||||
errors = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(errors);
|
||||
}
|
||||
|
||||
int
|
||||
rmdirp (char *path)
|
||||
{
|
||||
char *slash;
|
||||
|
||||
/* point slash at last slash */
|
||||
slash = strrchr (path, '/');
|
||||
|
||||
while (slash != NULL) {
|
||||
if (rmdir (path) < 0) {
|
||||
fprintf(stderr, "rmdir: %s: %s\n",
|
||||
path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* skip trailing slash characters */
|
||||
while (slash > path && *slash == '/')
|
||||
slash--;
|
||||
|
||||
*++slash = '\0';
|
||||
slash = strrchr (path, '/');
|
||||
}
|
||||
|
||||
if (rmdir (path) < 0) {
|
||||
fprintf(stderr, "rmdir: %s: %s\n", path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "usage: rmdir [-p] directory ...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue