7b76bb
From 80cdfba079627e15129a926a133825b961d41e36 Mon Sep 17 00:00:00 2001
7b76bb
From: Paul Eggert <eggert@cs.ucla.edu>
7b76bb
Date: Mon, 5 Mar 2018 10:56:29 -0800
7b76bb
Subject: [PATCH] fflush: adjust to glibc 2.28 libio.h removal
7b76bb
MIME-Version: 1.0
7b76bb
Content-Type: text/plain; charset=UTF-8
7b76bb
Content-Transfer-Encoding: 8bit
7b76bb
7b76bb
Problem reported by Daniel P. Berrangé in:
7b76bb
https://lists.gnu.org/r/bug-gnulib/2018-03/msg00000.html
7b76bb
* lib/fflush.c (clear_ungetc_buffer_preserving_position)
7b76bb
(disable_seek_optimization, rpl_fflush):
7b76bb
* lib/fpurge.c (fpurge):
7b76bb
* lib/freadahead.c (freadahead):
7b76bb
* lib/freading.c (freading):
7b76bb
* lib/fseeko.c (fseeko):
7b76bb
* lib/stdio-impl.h (_IO_IN_BACKUP) [_IO_EOF_SEEN]:
7b76bb
Define if not already defined.
7b76bb
7b76bb
Upstream-commit: 4af4a4a71827c0bc5e0ec67af23edef4f15cee8e
7b76bb
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
7b76bb
---
7b76bb
 gl/lib/fflush.c     | 6 +++---
7b76bb
 gl/lib/fpurge.c     | 2 +-
7b76bb
 gl/lib/freadahead.c | 2 +-
7b76bb
 gl/lib/freading.c   | 2 +-
7b76bb
 gl/lib/fseeko.c     | 4 ++--
7b76bb
 gl/lib/stdio-impl.h | 6 ++++++
7b76bb
 6 files changed, 14 insertions(+), 8 deletions(-)
7b76bb
7b76bb
diff --git a/gl/lib/fflush.c b/gl/lib/fflush.c
7b76bb
index 5ae3e41..7a82470 100644
7b76bb
--- a/gl/lib/fflush.c
7b76bb
+++ b/gl/lib/fflush.c
7b76bb
@@ -33,7 +33,7 @@
7b76bb
 #undef fflush
7b76bb
 
7b76bb
 
7b76bb
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
 
7b76bb
 /* Clear the stream's ungetc buffer, preserving the value of ftello (fp).  */
7b76bb
 static void
7b76bb
@@ -72,7 +72,7 @@ clear_ungetc_buffer (FILE *fp)
7b76bb
 
7b76bb
 #endif
7b76bb
 
7b76bb
-#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
7b76bb
+#if ! (defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
7b76bb
 
7b76bb
 # if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT
7b76bb
 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */
7b76bb
@@ -148,7 +148,7 @@ rpl_fflush (FILE *stream)
7b76bb
   if (stream == NULL || ! freading (stream))
7b76bb
     return fflush (stream);
7b76bb
 
7b76bb
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
 
7b76bb
   clear_ungetc_buffer_preserving_position (stream);
7b76bb
 
7b76bb
diff --git a/gl/lib/fpurge.c b/gl/lib/fpurge.c
7b76bb
index f313b22..ecdf82d 100644
7b76bb
--- a/gl/lib/fpurge.c
7b76bb
+++ b/gl/lib/fpurge.c
7b76bb
@@ -62,7 +62,7 @@ fpurge (FILE *fp)
7b76bb
   /* Most systems provide FILE as a struct and the necessary bitmask in
7b76bb
      <stdio.h>, because they need it for implementing getc() and putc() as
7b76bb
      fast macros.  */
7b76bb
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
   fp->_IO_read_end = fp->_IO_read_ptr;
7b76bb
   fp->_IO_write_ptr = fp->_IO_write_base;
7b76bb
   /* Avoid memory leak when there is an active ungetc buffer.  */
7b76bb
diff --git a/gl/lib/freadahead.c b/gl/lib/freadahead.c
7b76bb
index 094daab..3f8101e 100644
7b76bb
--- a/gl/lib/freadahead.c
7b76bb
+++ b/gl/lib/freadahead.c
7b76bb
@@ -25,7 +25,7 @@
7b76bb
 size_t
7b76bb
 freadahead (FILE *fp)
7b76bb
 {
7b76bb
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
   if (fp->_IO_write_ptr > fp->_IO_write_base)
7b76bb
     return 0;
7b76bb
   return (fp->_IO_read_end - fp->_IO_read_ptr)
7b76bb
diff --git a/gl/lib/freading.c b/gl/lib/freading.c
7b76bb
index 0512b19..8c48fe4 100644
7b76bb
--- a/gl/lib/freading.c
7b76bb
+++ b/gl/lib/freading.c
7b76bb
@@ -31,7 +31,7 @@ freading (FILE *fp)
7b76bb
   /* Most systems provide FILE as a struct and the necessary bitmask in
7b76bb
      <stdio.h>, because they need it for implementing getc() and putc() as
7b76bb
      fast macros.  */
7b76bb
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
   return ((fp->_flags & _IO_NO_WRITES) != 0
7b76bb
           || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
7b76bb
               && fp->_IO_read_base != NULL));
7b76bb
diff --git a/gl/lib/fseeko.c b/gl/lib/fseeko.c
7b76bb
index 1c65d2a..9026408 100644
7b76bb
--- a/gl/lib/fseeko.c
7b76bb
+++ b/gl/lib/fseeko.c
7b76bb
@@ -47,7 +47,7 @@ fseeko (FILE *fp, off_t offset, int whence)
7b76bb
 #endif
7b76bb
 
7b76bb
   /* These tests are based on fpurge.c.  */
7b76bb
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
   if (fp->_IO_read_end == fp->_IO_read_ptr
7b76bb
       && fp->_IO_write_ptr == fp->_IO_write_base
7b76bb
       && fp->_IO_save_base == NULL)
7b76bb
@@ -123,7 +123,7 @@ fseeko (FILE *fp, off_t offset, int whence)
7b76bb
           return -1;
7b76bb
         }
7b76bb
 
7b76bb
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
+#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
7b76bb
       fp->_flags &= ~_IO_EOF_SEEN;
7b76bb
       fp->_offset = pos;
7b76bb
 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
7b76bb
diff --git a/gl/lib/stdio-impl.h b/gl/lib/stdio-impl.h
7b76bb
index 502d891..ea38ee2 100644
7b76bb
--- a/gl/lib/stdio-impl.h
7b76bb
+++ b/gl/lib/stdio-impl.h
7b76bb
@@ -18,6 +18,12 @@
7b76bb
    the same implementation of stdio extension API, except that some fields
7b76bb
    have different naming conventions, or their access requires some casts.  */
7b76bb
 
7b76bb
+/* Glibc 2.28 made _IO_IN_BACKUP private.  For now, work around this
7b76bb
+   problem by defining it ourselves.  FIXME: Do not rely on glibc
7b76bb
+   internals.  */
7b76bb
+#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN
7b76bb
+# define _IO_IN_BACKUP 0x100
7b76bb
+#endif
7b76bb
 
7b76bb
 /* BSD stdio derived implementations.  */
7b76bb
 
7b76bb
-- 
7b76bb
2.16.2
7b76bb