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