summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/find/extern.h4
-rw-r--r--usr.bin/find/find.110
-rw-r--r--usr.bin/find/find.h10
-rw-r--r--usr.bin/find/function.c109
-rw-r--r--usr.bin/find/operator.c5
-rw-r--r--usr.bin/find/option.c6
6 files changed, 113 insertions, 31 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index df8dd472979..ed8e9cca7d0 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -1,4 +1,4 @@
-/* * $OpenBSD: extern.h,v 1.8 1997/11/13 08:30:32 deraadt Exp $*/
+/* * $OpenBSD: extern.h,v 1.9 1999/12/04 22:42:31 millert Exp $*/
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -51,8 +51,10 @@ int queryuser __P((char **));
void show_path __P((int));
PLAN *c_amin __P((char *));
+PLAN *c_anewer __P((char *));
PLAN *c_atime __P((char *));
PLAN *c_cmin __P((char *));
+PLAN *c_cnewer __P((char *));
PLAN *c_ctime __P((char *));
PLAN *c_depth __P((void));
PLAN *c_empty __P((void));
diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1
index f9270b46718..14360618dcd 100644
--- a/usr.bin/find/find.1
+++ b/usr.bin/find/find.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: find.1,v 1.23 1999/10/07 19:15:24 aaron Exp $
+.\" $OpenBSD: find.1,v 1.24 1999/12/04 22:42:31 millert Exp $
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -35,7 +35,7 @@
.\"
.\" from: @(#)find.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd August 31, 1996
+.Dd December 4, 1999
.Dt FIND 1
.Os
.Sh NAME
@@ -137,6 +137,9 @@ True if the difference between the file last access time and the time
was started, rounded up to the next full minute, is
.Ar n
minutes.
+.It Ic -anewer Ar file
+True if the current file has a more recent last access time than
+.Ar file .
.It Ic -atime Ar n
True if the difference between the file last access time and the time
.Nm
@@ -150,6 +153,9 @@ information and the time
was started, rounded up to the next full minute, is
.Ar n
minutes.
+.It Ic -cnewer Ar file
+True if the current file has a more recent last change time than
+.Ar file .
.It Ic -ctime Ar n
True if the difference between the time of last change of file status
information and the time
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index f754a06d421..314640ca405 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -1,4 +1,4 @@
-/* * $OpenBSD: find.h,v 1.7 1997/11/13 08:30:33 deraadt Exp $*/
+/* * $OpenBSD: find.h,v 1.8 1999/12/04 22:42:31 millert Exp $*/
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -40,8 +40,8 @@
/* node type */
enum ntype {
N_AND = 1, /* must start > 0 */
- N_AMIN, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CTIME, N_DEPTH,
- N_EMPTY, N_EXEC, N_EXECDIR,
+ N_AMIN, N_ANEWER, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, N_CTIME,
+ N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR,
N_EXPR, N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS,
N_MMIN, N_MAXDEPTH,
N_MINDEPTH, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER,
@@ -69,7 +69,7 @@ typedef struct _plandata {
mode_t _m_data; /* mode mask */
nlink_t _l_data; /* link count */
off_t _o_data; /* file size */
- time_t _t_data; /* time value */
+ struct timespec _t_data; /* time value */
uid_t _u_data; /* uid */
short _mt_data; /* mount flags */
struct _plandata *_p_data[2]; /* PLAN trees */
@@ -96,6 +96,8 @@ typedef struct _plandata {
#define o_data p_un._o_data
#define p_data p_un._p_data
#define t_data p_un._t_data
+#define sec_data p_un._t_data.tv_sec
+#define nsec_data p_un._t_data.tv_nsec
#define u_data p_un._u_data
#define e_argv p_un.ex._e_argv
#define e_orig p_un.ex._e_orig
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index f69043ec695..8754de6579a 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: function.c,v 1.16 1999/10/04 21:26:10 millert Exp $ */
+/* $OpenBSD: function.c,v 1.17 1999/12/04 22:42:32 millert 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.16 1999/10/04 21:26:10 millert Exp $";
+static char rcsid[] = "$OpenBSD: function.c,v 1.17 1999/12/04 22:42:32 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -134,7 +134,7 @@ find_parsenum(plan, option, vp, endch)
*/
#define TIME_CORRECT(p, ttype) \
if ((p)->type == ttype && (p)->flags == F_LESSTHAN) \
- ++((p)->t_data);
+ ++((p)->sec_data);
/*
* -amin n functions --
@@ -150,7 +150,7 @@ f_amin(plan, entry)
extern time_t now;
COMPARE((now - entry->fts_statp->st_atime +
- 60 - 1) / 60, plan->t_data);
+ 60 - 1) / 60, plan->sec_data);
}
PLAN *
@@ -162,7 +162,7 @@ c_amin(arg)
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_AMIN, f_amin);
- new->t_data = find_parsenum(new, "-amin", arg, NULL);
+ new->sec_data = find_parsenum(new, "-amin", arg, NULL);
TIME_CORRECT(new, N_AMIN);
return (new);
}
@@ -180,7 +180,7 @@ f_atime(plan, entry)
{
COMPARE((now - entry->fts_statp->st_atime +
- SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
+ SECSPERDAY - 1) / SECSPERDAY, plan->sec_data);
}
PLAN *
@@ -192,7 +192,7 @@ c_atime(arg)
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_ATIME, f_atime);
- new->t_data = find_parsenum(new, "-atime", arg, NULL);
+ new->sec_data = find_parsenum(new, "-atime", arg, NULL);
TIME_CORRECT(new, N_ATIME);
return (new);
}
@@ -211,7 +211,7 @@ f_cmin(plan, entry)
extern time_t now;
COMPARE((now - entry->fts_statp->st_ctime +
- 60 - 1) / 60, plan->t_data);
+ 60 - 1) / 60, plan->sec_data);
}
PLAN *
@@ -223,7 +223,7 @@ c_cmin(arg)
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_CMIN, f_cmin);
- new->t_data = find_parsenum(new, "-cmin", arg, NULL);
+ new->sec_data = find_parsenum(new, "-cmin", arg, NULL);
TIME_CORRECT(new, N_CMIN);
return (new);
}
@@ -241,7 +241,7 @@ f_ctime(plan, entry)
{
COMPARE((now - entry->fts_statp->st_ctime +
- SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
+ SECSPERDAY - 1) / SECSPERDAY, plan->sec_data);
}
PLAN *
@@ -253,7 +253,7 @@ c_ctime(arg)
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_CTIME, f_ctime);
- new->t_data = find_parsenum(new, "-ctime", arg, NULL);
+ new->sec_data = find_parsenum(new, "-ctime", arg, NULL);
TIME_CORRECT(new, N_CTIME);
return (new);
}
@@ -838,7 +838,7 @@ f_mtime(plan, entry)
{
COMPARE((now - entry->fts_statp->st_mtime + SECSPERDAY - 1) /
- SECSPERDAY, plan->t_data);
+ SECSPERDAY, plan->sec_data);
}
PLAN *
@@ -850,7 +850,7 @@ c_mtime(arg)
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_MTIME, f_mtime);
- new->t_data = find_parsenum(new, "-mtime", arg, NULL);
+ new->sec_data = find_parsenum(new, "-mtime", arg, NULL);
TIME_CORRECT(new, N_MTIME);
return (new);
}
@@ -869,7 +869,7 @@ f_mmin(plan, entry)
extern time_t now;
COMPARE((now - entry->fts_statp->st_mtime + 60 - 1) /
- 60, plan->t_data);
+ 60, plan->sec_data);
}
PLAN *
@@ -881,7 +881,7 @@ c_mmin(arg)
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_MMIN, f_mmin);
- new->t_data = find_parsenum(new, "-mmin", arg, NULL);
+ new->sec_data = find_parsenum(new, "-mmin", arg, NULL);
TIME_CORRECT(new, N_MMIN);
return (new);
}
@@ -923,7 +923,10 @@ f_newer(plan, entry)
PLAN *plan;
FTSENT *entry;
{
- return (entry->fts_statp->st_mtime > plan->t_data);
+
+ return (entry->fts_statp->st_mtimespec.tv_sec > plan->t_data.tv_sec ||
+ (entry->fts_statp->st_mtimespec.tv_sec == plan->t_data.tv_sec &&
+ entry->fts_statp->st_mtimespec.tv_nsec > plan->t_data.tv_nsec));
}
PLAN *
@@ -938,7 +941,75 @@ c_newer(filename)
if (stat(filename, &sb))
err(1, "%s", filename);
new = palloc(N_NEWER, f_newer);
- new->t_data = sb.st_mtime;
+ memcpy(&new->t_data, &sb.st_mtimespec, sizeof(struct timespec));
+ return (new);
+}
+
+/*
+ * -anewer file functions --
+ *
+ * True if the current file has been accessed more recently
+ * then the access time of the file named by the pathname
+ * file.
+ */
+int
+f_anewer(plan, entry)
+ PLAN *plan;
+ FTSENT *entry;
+{
+
+ return (entry->fts_statp->st_atimespec.tv_sec > plan->t_data.tv_sec ||
+ (entry->fts_statp->st_atimespec.tv_sec == plan->t_data.tv_sec &&
+ entry->fts_statp->st_atimespec.tv_nsec > plan->t_data.tv_nsec));
+}
+
+PLAN *
+c_anewer(filename)
+ char *filename;
+{
+ PLAN *new;
+ struct stat sb;
+
+ ftsoptions &= ~FTS_NOSTAT;
+
+ if (stat(filename, &sb))
+ err(1, "%s", filename);
+ new = palloc(N_NEWER, f_newer);
+ memcpy(&new->t_data, &sb.st_atimespec, sizeof(struct timespec));
+ return (new);
+}
+
+/*
+ * -cnewer file functions --
+ *
+ * True if the current file has been changed more recently
+ * then the inode change time of the file named by the pathname
+ * file.
+ */
+int
+f_cnewer(plan, entry)
+ PLAN *plan;
+ FTSENT *entry;
+{
+
+ return (entry->fts_statp->st_ctimespec.tv_sec > plan->t_data.tv_sec ||
+ (entry->fts_statp->st_ctimespec.tv_sec == plan->t_data.tv_sec &&
+ entry->fts_statp->st_ctimespec.tv_nsec > plan->t_data.tv_nsec));
+}
+
+PLAN *
+c_cnewer(filename)
+ char *filename;
+{
+ PLAN *new;
+ struct stat sb;
+
+ ftsoptions &= ~FTS_NOSTAT;
+
+ if (stat(filename, &sb))
+ err(1, "%s", filename);
+ new = palloc(N_NEWER, f_newer);
+ memcpy(&new->t_data, &sb.st_ctimespec, sizeof(struct timespec));
return (new);
}
@@ -1376,11 +1447,9 @@ palloc(t, f)
{
PLAN *new;
- if ((new = malloc(sizeof(PLAN)))) {
+ if ((new = calloc(1, sizeof(PLAN)))) {
new->type = t;
new->eval = f;
- new->flags = 0;
- new->next = NULL;
return (new);
}
err(1, NULL);
diff --git a/usr.bin/find/operator.c b/usr.bin/find/operator.c
index 6fa4372bc69..d9253e922ab 100644
--- a/usr.bin/find/operator.c
+++ b/usr.bin/find/operator.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: operator.c,v 1.4 1999/01/04 21:36:01 millert Exp $ */
+/* $OpenBSD: operator.c,v 1.5 1999/12/04 22:42:32 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,10 +38,11 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)operator.c 8.1 (Berkeley) 6/6/93";*/
-static char rcsid[] = "$OpenBSD: operator.c,v 1.4 1999/01/04 21:36:01 millert Exp $";
+static char rcsid[] = "$OpenBSD: operator.c,v 1.5 1999/12/04 22:42:32 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
+#include <sys/stat.h>
#include <err.h>
#include <fts.h>
diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c
index 3ba9338f390..b6a99231038 100644
--- a/usr.bin/find/option.c
+++ b/usr.bin/find/option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: option.c,v 1.8 1997/11/28 09:39:17 deraadt Exp $ */
+/* $OpenBSD: option.c,v 1.9 1999/12/04 22:42:32 millert 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.8 1997/11/28 09:39:17 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: option.c,v 1.9 1999/12/04 22:42:32 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -59,9 +59,11 @@ static OPTION options[] = {
{ ")", N_CLOSEPAREN, c_closeparen, O_ZERO },
{ "-a", N_AND, NULL, O_NONE },
{ "-amin", N_AMIN, c_amin, O_ARGV },
+ { "-anewer", N_ANEWER, c_anewer, O_ARGV },
{ "-and", N_AND, NULL, O_NONE },
{ "-atime", N_ATIME, c_atime, O_ARGV },
{ "-cmin", N_CMIN, c_cmin, O_ARGV },
+ { "-cnewer", N_CNEWER, c_cnewer, O_ARGV },
{ "-ctime", N_CTIME, c_ctime, O_ARGV },
{ "-depth", N_DEPTH, c_depth, O_ZERO },
{ "-empty", N_EMPTY, c_empty, O_ZERO },