-Wall cleaning and implement -p commandline option.
-p mod obtained from: NetBSD
This commit is contained in:
parent
1f64b5c98e
commit
11bde14e4f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=20422
@ -33,7 +33,7 @@
|
|||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" @(#)rmdir.1 8.1 (Berkeley) 5/31/93
|
.\" @(#)rmdir.1 8.1 (Berkeley) 5/31/93
|
||||||
.\" $Id: rmdir.1,v 1.2 1994/09/24 02:57:11 davidg Exp $
|
.\" $Id: rmdir.1,v 1.3 1996/08/29 18:06:08 wosch Exp $
|
||||||
.\"
|
.\"
|
||||||
.Dd May 31, 1993
|
.Dd May 31, 1993
|
||||||
.Dt RMDIR 1
|
.Dt RMDIR 1
|
||||||
@ -43,7 +43,7 @@
|
|||||||
.Nd remove directories
|
.Nd remove directories
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rmdir
|
.Nm rmdir
|
||||||
.\" .Op Fl p
|
.Op Fl p
|
||||||
.Ar directory ...
|
.Ar directory ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The rmdir utility removes the directory entry specified by
|
The rmdir utility removes the directory entry specified by
|
||||||
@ -58,24 +58,24 @@ must be specified first so the parent directory
|
|||||||
is empty when
|
is empty when
|
||||||
.Nm rmdir
|
.Nm rmdir
|
||||||
tries to remove it.
|
tries to remove it.
|
||||||
.\" .Pp
|
.Pp
|
||||||
.\" The following option is available:
|
The following option is available:
|
||||||
.\" .Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.\" .It Fl p
|
.It Fl p
|
||||||
.\" Each
|
Each
|
||||||
.\" .Ar directory
|
.Ar directory
|
||||||
.\" argument is treated as a pathname of which all
|
argument is treated as a pathname of which all
|
||||||
.\" components will be removed, if they are empty,
|
components will be removed, if they are empty,
|
||||||
.\" starting with the last most component.
|
starting with the last most component.
|
||||||
.\" (See
|
(See
|
||||||
.\" .Xr rm 1
|
.Xr rm 1
|
||||||
.\" for fully non-discriminant recursive removal).
|
for fully non-discriminant recursive removal.)
|
||||||
.\" .El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Nm rmdir
|
.Nm rmdir
|
||||||
utility exits with one of the following values:
|
utility exits with one of the following values:
|
||||||
.Bl -tag -width flag
|
.Bl -tag -width Ds
|
||||||
.It Li \&0
|
.It Li \&0
|
||||||
Each directory entry specified by a dir operand
|
Each directory entry specified by a dir operand
|
||||||
referred to an empty directory and was removed
|
referred to an empty directory and was removed
|
||||||
|
@ -30,17 +30,17 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id: rmdir.c,v 1.2 1994/09/24 02:57:13 davidg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static char const copyright[] =
|
||||||
"@(#) Copyright (c) 1992, 1993, 1994\n\
|
"@(#) Copyright (c) 1992, 1993, 1994\n\
|
||||||
The Regents of the University of California. All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
|
static char const sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
@ -50,6 +50,7 @@ static char sccsid[] = "@(#)rmdir.c 8.3 (Berkeley) 4/2/94";
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int rm_path __P((char *));
|
||||||
void usage __P((void));
|
void usage __P((void));
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -58,9 +59,14 @@ main(argc, argv)
|
|||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
int ch, errors;
|
int ch, errors;
|
||||||
|
int pflag;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "")) != EOF)
|
pflag = 0;
|
||||||
|
while ((ch = getopt(argc, argv, "p")) != EOF)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
|
case 'p':
|
||||||
|
pflag = 1;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -71,18 +77,50 @@ main(argc, argv)
|
|||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
for (errors = 0; *argv; ++argv)
|
for (errors = 0; *argv; argv++) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
/* Delete trailing slashes, per POSIX. */
|
||||||
|
p = *argv + strlen(*argv);
|
||||||
|
while (--p > *argv && *p == '/')
|
||||||
|
;
|
||||||
|
*++p = '\0';
|
||||||
|
|
||||||
if (rmdir(*argv) < 0) {
|
if (rmdir(*argv) < 0) {
|
||||||
warn("%s", *argv);
|
warn("%s", *argv);
|
||||||
errors = 1;
|
errors = 1;
|
||||||
}
|
} else if (pflag)
|
||||||
|
errors |= rm_path(*argv);
|
||||||
|
}
|
||||||
|
|
||||||
exit(errors);
|
exit(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rm_path(path)
|
||||||
|
char *path;
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
while ((p = strrchr(path, '/')) != NULL) {
|
||||||
|
/* Delete trailing slashes. */
|
||||||
|
while (--p > path && *p == '/')
|
||||||
|
;
|
||||||
|
*++p = '\0';
|
||||||
|
|
||||||
|
if (rmdir(path) < 0) {
|
||||||
|
warn("%s", path);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
|
|
||||||
(void)fprintf(stderr, "usage: rmdir directory ...\n");
|
(void)fprintf(stderr, "usage: rmdir [-p] directory ...\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user