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