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