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