* m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): Guess no on NetBSD and
OpenBSD; they document fflush to fail unless the stream is open
for writing.
---
 ChangeLog                       |  7 +++++++
 doc/posix-functions/fflush.texi |  3 +++
 m4/fflush.m4                    | 11 ++++++-----
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b2f3e3ffb6..d65e8cb88d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-09-16  Paul Eggert  <egg...@cs.ucla.edu>
+
+       fflush: NetBSD, OpenBSD can’t fflush input
+       * m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): Guess no on NetBSD and
+       OpenBSD; they document fflush to fail unless the stream is open
+       for writing.
+
 2024-09-16  Bruno Haible  <br...@clisp.org>
 
        unictype/category-of: Fix integer overflow in generated table.
diff --git a/doc/posix-functions/fflush.texi b/doc/posix-functions/fflush.texi
index 0f6b700172..39f8ae9739 100644
--- a/doc/posix-functions/fflush.texi
+++ b/doc/posix-functions/fflush.texi
@@ -20,6 +20,9 @@ end of the previous buffer, on some platforms: mingw, MSVC 14.
 @code{fflush} on an input stream right after @code{ungetc} does not discard
 the @code{ungetc} buffer, on some platforms:
 macOS 14, FreeBSD 6.0, NetBSD 10.0, OpenBSD 7.5, Cygwin 1.5.25-10.
+@item
+@code{fflush} fails with @code{EBADF} if the stream is not open for writing:
+NetBSD 10.0, OpenBSD 7.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/fflush.m4 b/m4/fflush.m4
index 43fc3bf346..1b30fb91d4 100644
--- a/m4/fflush.m4
+++ b/m4/fflush.m4
@@ -1,5 +1,5 @@
 # fflush.m4
-# serial 19
+# serial 20
 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -79,8 +79,9 @@ AC_DEFUN([gl_FUNC_FFLUSH_STDIN],
        [gl_cv_func_fflush_stdin=yes],
        [gl_cv_func_fflush_stdin=no],
        [case "$host_os" in
-                             # Guess no on native Windows.
-          mingw* | windows*) gl_cv_func_fflush_stdin="guessing no" ;;
+                             # Guess no on NetBSD, OpenBSD, native Windows.
+          netbsd* | openbsd* | mingw* | windows*)
+                             gl_cv_func_fflush_stdin="guessing no" ;;
           *)                 gl_cv_func_fflush_stdin=cross ;;
         esac
        ])
@@ -92,8 +93,8 @@ AC_DEFUN([gl_FUNC_FFLUSH_STDIN],
     *)    gl_func_fflush_stdin='(-1)' ;;
   esac
   AC_DEFINE_UNQUOTED([FUNC_FFLUSH_STDIN], [$gl_func_fflush_stdin],
-    [Define to 1 if fflush is known to work on stdin as per POSIX.1-2008,
-     0 if fflush is known to not work, -1 if unknown.])
+    [Define to 1 if fflush is known to work on stdin as per POSIX.1-2008
+     or later, 0 if fflush is known to not work, -1 if unknown.])
 ])
 
 # Prerequisites of lib/fflush.c.
-- 
2.43.0


Reply via email to