-/* * $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.
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 *));
-.\" $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.
.\"
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
-/* * $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.
/* 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,
};
-/* $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
#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>
#include <sys/wait.h>
#include <sys/mount.h>
+#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <fnmatch.h>
return (palloc(N_DEPTH, f_always_true));
}
+/*
+ * -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 --
*
-/* $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
#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>
{ "-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 },