--- find.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/find.c b/find.c index ef28232..7243072 100644 --- a/find.c +++ b/find.c _AT_@ -112,6 +112,7 @@ struct findhist { /* Utility */ static int spawn(char *argv[]); +static int do_stat(char *path, struct stat *sb, struct findhist *hist); /* Primaries */ static int pri_name (struct arg *arg); _AT_@ -254,6 +255,20 @@ spawn(char *argv[]) return status; } +static int +do_stat(char *path, struct stat *sb, struct findhist *hist) +{ + if (gflags.l || (gflags.h && !hist)) { + if (stat(path, sb) == 0) { + return 0; + } else if (errno != ENOENT && errno != ENOTDIR) { + return -1; + } + } + + return lstat(path, sb); +} + /* * Primaries */ _AT_@ -664,7 +679,7 @@ get_newer_arg(char *argv[], union extra *extra) { struct stat st; - if (stat(*argv, &st)) + if (do_stat(*argv, &st, NULL)) eprintf("failed to stat '%s':", *argv); extra->i = st.st_mtime; _AT_@ -943,7 +958,7 @@ find(char *path, struct findhist *hist) len = strlen(path) + 2; /* \0 and '/' */ - if ((gflags.l || (gflags.h && !hist) ? stat(path, &st) : lstat(path, &st)) < 0) { + if (do_stat(path, &st, hist) < 0) { weprintf("failed to stat %s:", path); return; } -- 2.48.1Received on Fri Feb 14 2025 - 16:55:16 CET
This archive was generated by hypermail 2.3.0 : Fri Feb 14 2025 - 18:36:37 CET