diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/find/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/find/find.1 | 4 | ||||
-rw-r--r-- | usr.bin/find/find.h | 10 | ||||
-rw-r--r-- | usr.bin/find/function.c | 47 | ||||
-rw-r--r-- | usr.bin/find/option.c | 5 |
5 files changed, 58 insertions, 11 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 993f2d7ad67..9c1d2576b32 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: extern.h,v 1.4 1996/09/01 04:30:15 tholo Exp $*/ +/* * $OpenBSD: extern.h,v 1.5 1996/09/01 04:56:25 tholo Exp $*/ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -52,6 +52,7 @@ int queryuser __P((char **)); PLAN *c_atime __P((char *)); PLAN *c_ctime __P((char *)); PLAN *c_depth __P((void)); +PLAN *c_empty __P((void)); PLAN *c_exec __P((char ***, int)); PLAN *c_follow __P((void)); PLAN *c_fstype __P((char *)); diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index 18ef89b48fb..aab0a59fb92 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: find.1,v 1.7 1996/09/01 04:30:16 tholo Exp $ +.\" $OpenBSD: find.1,v 1.8 1996/09/01 04:56:25 tholo Exp $ .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -142,6 +142,8 @@ information and the time was started, rounded up to the next full 24\-hour period, is .Ar n 24\-hour periods. +.It Ic -empty +True if the current file or directory is empty. .It Ic -exec Ar utility Op argument ... ; True if the program named .Ar utility diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h index 20a41d6f7a5..b1b71021186 100644 --- a/usr.bin/find/find.h +++ b/usr.bin/find/find.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: find.h,v 1.4 1996/09/01 04:30:16 tholo Exp $*/ +/* * $OpenBSD: find.h,v 1.5 1996/09/01 04:56:26 tholo Exp $*/ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -40,10 +40,10 @@ /* node type */ enum ntype { N_AND = 1, /* must start > 0 */ - N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EXEC, N_EXPR, N_FOLLOW, - N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MAXDEPTH, N_MINDEPTH, - N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, - N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRUNE, + N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EMPTY, N_EXEC, N_EXPR, + N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MAXDEPTH, + N_MINDEPTH, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, + N_OK, N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, }; diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 42a4506d022..9264442dd1f 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.6 1996/09/01 04:30:17 tholo Exp $ */ +/* $OpenBSD: function.c,v 1.7 1996/09/01 04:56:26 tholo Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: function.c,v 1.6 1996/09/01 04:30:17 tholo Exp $"; +static char rcsid[] = "$OpenBSD: function.c,v 1.7 1996/09/01 04:56:26 tholo Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -47,6 +47,7 @@ static char rcsid[] = "$OpenBSD: function.c,v 1.6 1996/09/01 04:30:17 tholo Exp #include <sys/wait.h> #include <sys/mount.h> +#include <dirent.h> #include <err.h> #include <errno.h> #include <fnmatch.h> @@ -214,6 +215,48 @@ c_depth() } /* + * -empty functions -- + * + * True if the file or directory is empty + */ +int +f_empty(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + if (S_ISREG(entry->fts_statp->st_mode) && entry->fts_statp->st_size == 0) + return (1); + if (S_ISDIR(entry->fts_statp->st_mode)) { + struct dirent *dp; + int empty; + DIR *dir; + + empty = 1; + dir = opendir(entry->fts_accpath); + if (dir == NULL) + err(1, "%s", entry->fts_accpath); + for (dp = readdir(dir); dp; dp = readdir(dir)) + if (dp->d_name[0] != '.' || + (dp->d_name[1] != '\0' && + (dp->d_name[1] != '.' || dp->d_name[2] != '\0'))) { + empty = 0; + break; + } + closedir(dir); + return (empty); + } + return (0); +} + +PLAN * +c_empty() +{ + ftsoptions &= ~FTS_NOSTAT; + + return (palloc(N_EMPTY, f_empty)); +} + +/* * [-exec | -ok] utility [arg ... ] ; functions -- * * True if the executed utility returns a zero value as exit status. diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index 6d7d123dfd8..d5db954baa2 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: option.c,v 1.4 1996/09/01 04:30:17 tholo Exp $ */ +/* $OpenBSD: option.c,v 1.5 1996/09/01 04:56:27 tholo Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)option.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: option.c,v 1.4 1996/09/01 04:30:17 tholo Exp $"; +static char rcsid[] = "$OpenBSD: option.c,v 1.5 1996/09/01 04:56:27 tholo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -62,6 +62,7 @@ static OPTION options[] = { { "-atime", N_ATIME, c_atime, O_ARGV }, { "-ctime", N_CTIME, c_ctime, O_ARGV }, { "-depth", N_DEPTH, c_depth, O_ZERO }, + { "-empty", N_EMPTY, c_empty, O_ZERO }, { "-exec", N_EXEC, c_exec, O_ARGVP }, { "-follow", N_FOLLOW, c_follow, O_ZERO }, { "-fstype", N_FSTYPE, c_fstype, O_ARGV }, |