From a3de4bd9622c1bc2619f907d1b83ba650c7dc653 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Wed, 24 Nov 2021 01:57:35 +0100
Subject: [PATCH] find: allow -files0-from input file to be empty

Do no longer output an error diagnostic when the input file of
the -files0-from option is empty.

* find/ftsfind.c (process_all_startpoints): Remove error diagnostic.
* doc/find.texi (node Starting points): Adjust documentation.
* find/find.1: Likewise.
* tests/find/files0-from.sh: Adjust test.

Suggested by Stephane Chazelas in
https://savannah.gnu.org/bugs/?60383#comment11
---
 doc/find.texi             |  7 +++++--
 find/find.1               |  7 +++++--
 find/ftsfind.c            |  4 ----
 tests/find/files0-from.sh | 12 ++++++------
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/doc/find.texi b/doc/find.texi
index 69572b78..cb7ac9f4 100644
--- a/doc/find.texi
+++ b/doc/find.texi
@@ -410,8 +410,11 @@ The starting points in @file{file} have to be separated by ASCII NUL characters.
 Two consecutive NUL characters, i.e., a starting point with a Zero-length
 file name is not allowed and will lead to an error diagnostic followed by
 a non-Zero exit code later.
-The given @file{file} has to contain at least one starting point,
-i.e., an empty input file will be diagnosed as well.
+
+In the case the given @file{file} is empty, @code{find} will not process any
+starting point and exit immediately after parsing the options.
+This is a difference to the traditional invocation where @code{find} assumes
+the current directory as starting point if no path argument is passed.
 
 The processing of the starting points is otherwise as usual, e.g. @code{find}
 will recurse into subdirectories unless otherwise prevented.
diff --git a/find/find.1 b/find/find.1
index 004e9b23..5adff58d 100644
--- a/find/find.1
+++ b/find/find.1
@@ -539,8 +539,11 @@ The starting points in \fIfile\fR have to be separated by ASCII NUL characters.
 Two consecutive NUL characters, i.e., a starting point with a Zero-length
 file name is not allowed and will lead to an error diagnostic followed by
 a non-Zero exit code later.
-The given \fIfile\fR has to contain at least one starting point,
-i.e., an empty input file will be diagnosed as well.
+
+In the case the given \fIfile\fR is empty, \fBfind\fR will not process any
+starting point and exit immediately after parsing the options.
+This is a difference to the traditional invocation where\fBfind\fR assumes
+the current directory as starting point if no path argument is passed.
 
 The processing of the starting points is otherwise as usual, e.g.
 .B find
diff --git a/find/ftsfind.c b/find/ftsfind.c
index bd3b8ee8..b266a988 100644
--- a/find/ftsfind.c
+++ b/find/ftsfind.c
@@ -713,10 +713,6 @@ process_all_startpoints (int argc, char *argv[])
     }
  argv_iter_done:
 
-  if (ok && options.files0_from && argv_iter_n_args (ai) <= 0)
-    die (EXIT_FAILURE, 0, _("file with starting points is empty: %s"),
-         files0_filename_quoted);
-
   argv_iter_free (ai);
 
   if (ok && options.files0_from && (ferror (stream) || fclose (stream) != 0))
diff --git a/tests/find/files0-from.sh b/tests/find/files0-from.sh
index bf54a1b2..4864a866 100755
--- a/tests/find/files0-from.sh
+++ b/tests/find/files0-from.sh
@@ -94,19 +94,19 @@ returns_ 1 find -files0-from / > out 2> err \
   || { grep . out err; fail=1; }
 
 # Exercise an empty input file.
-returns_ 1 find -files0-from /dev/null > out 2> err || fail=1
+find -files0-from /dev/null > out 2> err || fail=1
 compare /dev/null out || fail=1
-grep 'file with starting points is empty:' err || fail=1
+compare /dev/null err || fail=1
 
 # Likewise via stdin.
-returns_ 1 find -files0-from - < /dev/null > out 2> err || fail=1
+find -files0-from - < /dev/null > out 2> err || fail=1
 compare /dev/null out || fail=1
-grep 'file with starting points is empty:.*standard input' err || fail=1
+compare /dev/null err || fail=1
 
 # Likewise via a pipe on stdin.
-cat /dev/null | returns_ 1 find -files0-from - > out 2> err || fail=1
+cat /dev/null | find -files0-from - > out 2> err || fail=1
 compare /dev/null out || fail=1
-grep 'file with starting points is empty:.*standard input' err || fail=1
+compare /dev/null err || fail=1
 
 # With the -files0-from option, now a closing paren could be passed as first
 # predicate (without, it is treated as a starting point).  Ensure that find(1)
-- 
2.33.1

