b5844f
From 1831628c0630ae96a43586b2a25ca51cbdba3e53 Mon Sep 17 00:00:00 2001
b5844f
From: Paul Eggert <address@hidden>
b5844f
Date: Mon, 5 Mar 2018 10:56:29 -0800
b5844f
Subject: [PATCH] fflush: adjust to glibc 2.28 libio.h removal
b5844f
MIME-Version: 1.0
b5844f
Content-Type: text/plain; charset=UTF-8
b5844f
Content-Transfer-Encoding: 8bit
b5844f
b5844f
Problem reported by Daniel P. Berrangé in:
b5844f
https://lists.gnu.org/r/bug-gnulib/2018-03/msg00000.html
b5844f
* lib/fbufmode.c (fbufmode):
b5844f
* lib/fflush.c (clear_ungetc_buffer_preserving_position)
b5844f
(disable_seek_optimization, rpl_fflush):
b5844f
* lib/fpending.c (__fpending):
b5844f
* lib/fpurge.c (fpurge):
b5844f
* lib/freadable.c (freadable):
b5844f
* lib/freadahead.c (freadahead):
b5844f
* lib/freading.c (freading):
b5844f
* lib/freadptr.c (freadptr):
b5844f
* lib/freadseek.c (freadptrinc):
b5844f
* lib/fseeko.c (fseeko):
b5844f
* lib/fseterr.c (fseterr):
b5844f
* lib/fwritable.c (fwritable):
b5844f
* lib/fwriting.c (fwriting):
b5844f
Check _IO_EOF_SEEN instead of _IO_ftrylockfile.
b5844f
* lib/stdio-impl.h (_IO_IN_BACKUP) [_IO_EOF_SEEN]:
b5844f
Define if not already defined.
b5844f
---
b5844f
 ChangeLog        | 23 +++++++++++++++++++++++
b5844f
 lib/fbufmode.c   |  2 +-
b5844f
 lib/fflush.c     |  6 +++---
b5844f
 lib/fpending.c   |  2 +-
b5844f
 lib/fpurge.c     |  2 +-
b5844f
 lib/freadable.c  |  2 +-
b5844f
 lib/freadahead.c |  2 +-
b5844f
 lib/freading.c   |  2 +-
b5844f
 lib/freadptr.c   |  2 +-
b5844f
 lib/freadseek.c  |  2 +-
b5844f
 lib/fseeko.c     |  4 ++--
b5844f
 lib/fseterr.c    |  2 +-
b5844f
 lib/fwritable.c  |  2 +-
b5844f
 lib/fwriting.c   |  2 +-
b5844f
 lib/stdio-impl.h |  6 ++++++
b5844f
 15 files changed, 45 insertions(+), 16 deletions(-)
b5844f
b5844f
diff --git a/ChangeLog b/ChangeLog
b5844f
index 667f91663..beb835670 100644
b5844f
--- a/ChangeLog
b5844f
+++ b/ChangeLog
b5844f
@@ -1,3 +1,26 @@
b5844f
+2018-03-05  Paul Eggert  <address@hidden>
b5844f
+
b5844f
+	fflush: adjust to glibc 2.28 libio.h removal
b5844f
+	Problem reported by Daniel P. Berrangé in:
b5844f
+	https://lists.gnu.org/r/bug-gnulib/2018-03/msg00000.html
b5844f
+	* lib/fbufmode.c (fbufmode):
b5844f
+	* lib/fflush.c (clear_ungetc_buffer_preserving_position)
b5844f
+	(disable_seek_optimization, rpl_fflush):
b5844f
+	* lib/fpending.c (__fpending):
b5844f
+	* lib/fpurge.c (fpurge):
b5844f
+	* lib/freadable.c (freadable):
b5844f
+	* lib/freadahead.c (freadahead):
b5844f
+	* lib/freading.c (freading):
b5844f
+	* lib/freadptr.c (freadptr):
b5844f
+	* lib/freadseek.c (freadptrinc):
b5844f
+	* lib/fseeko.c (fseeko):
b5844f
+	* lib/fseterr.c (fseterr):
b5844f
+	* lib/fwritable.c (fwritable):
b5844f
+	* lib/fwriting.c (fwriting):
b5844f
+	Check _IO_EOF_SEEN instead of _IO_ftrylockfile.
b5844f
+	* lib/stdio-impl.h (_IO_IN_BACKUP) [_IO_EOF_SEEN]:
b5844f
+	Define if not already defined.
b5844f
+
b5844f
 2018-01-07  Jim Meyering  <meyering@fb.com>
b5844f
 
b5844f
 	version 1.9
b5844f
 	* NEWS: Record release date.
b5844f
diff --git a/lib/fflush.c b/lib/fflush.c
b5844f
index 983ade0ff..a6edfa105 100644
b5844f
--- a/lib/fflush.c
b5844f
+++ b/lib/fflush.c
b5844f
@@ -33,7 +33,7 @@
b5844f
 #undef fflush
b5844f
 
b5844f
 
b5844f
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
 
b5844f
 /* Clear the stream's ungetc buffer, preserving the value of ftello (fp).  */
b5844f
 static void
b5844f
@@ -72,7 +72,7 @@ clear_ungetc_buffer (FILE *fp)
b5844f
 
b5844f
 #endif
b5844f
 
b5844f
-#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
b5844f
+#if ! (defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
b5844f
 
b5844f
 # if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
b5844f
 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
b5844f
@@ -148,7 +148,7 @@ rpl_fflush (FILE *stream)
b5844f
   if (stream == NULL || ! freading (stream))
b5844f
     return fflush (stream);
b5844f
 
b5844f
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
 
b5844f
   clear_ungetc_buffer_preserving_position (stream);
b5844f
 
b5844f
diff --git a/lib/fpurge.c b/lib/fpurge.c
b5844f
index b1d417c7a..3aedcc373 100644
b5844f
--- a/lib/fpurge.c
b5844f
+++ b/lib/fpurge.c
b5844f
@@ -62,7 +62,7 @@ fpurge (FILE *fp)
b5844f
   /* Most systems provide FILE as a struct and the necessary bitmask in
b5844f
      <stdio.h>, because they need it for implementing getc() and putc() as
b5844f
      fast macros.  */
b5844f
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
   fp->_IO_read_end = fp->_IO_read_ptr;
b5844f
   fp->_IO_write_ptr = fp->_IO_write_base;
b5844f
   /* Avoid memory leak when there is an active ungetc buffer.  */
b5844f
diff --git a/lib/freading.c b/lib/freading.c
b5844f
index 73c28acdd..c24d0c88a 100644
b5844f
--- a/lib/freading.c
b5844f
+++ b/lib/freading.c
b5844f
@@ -31,7 +31,7 @@ freading (FILE *fp)
b5844f
   /* Most systems provide FILE as a struct and the necessary bitmask in
b5844f
      <stdio.h>, because they need it for implementing getc() and putc() as
b5844f
      fast macros.  */
b5844f
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
   return ((fp->_flags & _IO_NO_WRITES) != 0
b5844f
           || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
b5844f
               && fp->_IO_read_base != NULL));
b5844f
diff --git a/lib/fseeko.c b/lib/fseeko.c
b5844f
index 0101ab55f..193f4e8ce 100644
b5844f
--- a/lib/fseeko.c
b5844f
+++ b/lib/fseeko.c
b5844f
@@ -47,7 +47,7 @@ fseeko (FILE *fp, off_t offset, int whence)
b5844f
 #endif
b5844f
 
b5844f
   /* These tests are based on fpurge.c.  */
b5844f
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
   if (fp->_IO_read_end == fp->_IO_read_ptr
b5844f
       && fp->_IO_write_ptr == fp->_IO_write_base
b5844f
       && fp->_IO_save_base == NULL)
b5844f
@@ -123,7 +123,7 @@ fseeko (FILE *fp, off_t offset, int whence)
b5844f
           return -1;
b5844f
         }
b5844f
 
b5844f
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
       fp->_flags &= ~_IO_EOF_SEEN;
b5844f
       fp->_offset = pos;
b5844f
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
b5844f
diff --git a/lib/fseterr.c b/lib/fseterr.c
b5844f
index 82649c3ac..adb637256 100644
b5844f
--- a/lib/fseterr.c
b5844f
+++ b/lib/fseterr.c
b5844f
@@ -29,7 +29,7 @@ fseterr (FILE *fp)
b5844f
   /* Most systems provide FILE as a struct and the necessary bitmask in
b5844f
      <stdio.h>, because they need it for implementing getc() and putc() as
b5844f
      fast macros.  */
b5844f
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
b5844f
   fp->_flags |= _IO_ERR_SEEN;
b5844f
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
b5844f
   /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
b5844f
diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
b5844f
index 78d896e9f..05c5752a2 100644
b5844f
--- a/lib/stdio-impl.h
b5844f
+++ b/lib/stdio-impl.h
b5844f
@@ -18,6 +18,12 @@
b5844f
    the same implementation of stdio extension API, except that some fields
b5844f
    have different naming conventions, or their access requires some casts.  */
b5844f
 
b5844f
+/* Glibc 2.28 made _IO_IN_BACKUP private.  For now, work around this
b5844f
+   problem by defining it ourselves.  FIXME: Do not rely on glibc
b5844f
+   internals.  */
b5844f
+#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN
b5844f
+# define _IO_IN_BACKUP 0x100
b5844f
+#endif
b5844f
 
b5844f
 /* BSD stdio derived implementations.  */
b5844f
 
b5844f
-- 
b5844f
2.14.3
b5844f