From: Liam J. Foy Date: Mon, 24 Jan 2005 18:58:20 +0000 (+0000) Subject: - Add -v option (verbose). Taken from FreeBSD with my modifications. X-Git-Tag: v2.0.1~9052 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/f148ab8cc342392db316645147d95202804398af - Add -v option (verbose). Taken from FreeBSD with my modifications. - Remove unnecessary header (errno.h) - Static functions - Add new -v option to man page --- diff --git a/bin/rmdir/rmdir.1 b/bin/rmdir/rmdir.1 index 1d4405c11b..58659cf9cf 100644 --- a/bin/rmdir/rmdir.1 +++ b/bin/rmdir/rmdir.1 @@ -34,9 +34,9 @@ .\" .\" @(#)rmdir.1 8.1 (Berkeley) 5/31/93 .\" $FreeBSD: src/bin/rmdir/rmdir.1,v 1.8.2.1 2000/12/08 13:34:40 ru Exp $ -.\" $DragonFly: src/bin/rmdir/rmdir.1,v 1.2 2003/06/17 04:22:50 dillon Exp $ +.\" $DragonFly: src/bin/rmdir/rmdir.1,v 1.3 2005/01/24 18:58:20 liamfoy Exp $ .\" -.Dd May 31, 1993 +.Dd January 24, 2005 .Dt RMDIR 1 .Os .Sh NAME @@ -44,7 +44,7 @@ .Nd remove directories .Sh SYNOPSIS .Nm -.Op Fl p +.Op Fl pv .Ar directory ... .Sh DESCRIPTION The @@ -73,6 +73,8 @@ starting with the last most component. (See .Xr rm 1 for fully non-discriminant recursive removal.) +.It Fl v +Be verbose, listing each directory as it is removed. .El .Pp The diff --git a/bin/rmdir/rmdir.c b/bin/rmdir/rmdir.c index 2d5d1a1dda..2beb3927e3 100644 --- a/bin/rmdir/rmdir.c +++ b/bin/rmdir/rmdir.c @@ -33,18 +33,19 @@ * @(#) Copyright (c) 1992, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)rmdir.c 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/bin/rmdir/rmdir.c,v 1.9.2.2 2001/08/01 05:16:47 obrien Exp $ - * $DragonFly: src/bin/rmdir/rmdir.c,v 1.6 2004/11/07 20:54:52 eirikn Exp $ + * $DragonFly: src/bin/rmdir/rmdir.c,v 1.7 2005/01/24 18:58:20 liamfoy Exp $ */ #include -#include #include #include #include #include -int rm_path (char *); -void usage (void); +static int rm_path(char *); +static void usage(void); + +static int vflag; int main(int argc, char **argv) @@ -53,11 +54,14 @@ main(int argc, char **argv) int pflag; pflag = 0; - while ((ch = getopt(argc, argv, "p")) != -1) + while ((ch = getopt(argc, argv, "pv")) != -1) switch(ch) { case 'p': pflag = 1; break; + case 'v': + vflag = 1; + break; case '?': default: usage(); @@ -72,14 +76,19 @@ main(int argc, char **argv) if (rmdir(*argv) < 0) { warn("%s", *argv); errors = 1; - } else if (pflag) - errors |= rm_path(*argv); + } else { + if (vflag) + printf("removed: %s\n", *argv); + + if (pflag) + errors |= rm_path(*argv); + } } exit(errors); } -int +static int rm_path(char *path) { char *p; @@ -97,16 +106,17 @@ rm_path(char *path) if (rmdir(path) < 0) { warn("%s", path); return (1); + } else if (vflag) { + printf("removed: %s\n", path); } } return (0); } -void +static void usage(void) { - - fprintf(stderr, "usage: rmdir [-p] directory ...\n"); + fprintf(stderr, "usage: rmdir [-pv] directory ...\n"); exit(1); }