Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 80cdfba079627e15129a926a133825b961d41e36 Mon Sep 17 00:00:00 2001 |
| 2 | From: Paul Eggert <eggert@cs.ucla.edu> |
| 3 | Date: Mon, 5 Mar 2018 10:56:29 -0800 |
| 4 | Subject: [PATCH] fflush: adjust to glibc 2.28 libio.h removal |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | Problem reported by Daniel P. Berrangé in: |
| 10 | https://lists.gnu.org/r/bug-gnulib/2018-03/msg00000.html |
| 11 | * lib/fflush.c (clear_ungetc_buffer_preserving_position) |
| 12 | (disable_seek_optimization, rpl_fflush): |
| 13 | * lib/fpurge.c (fpurge): |
| 14 | * lib/freadahead.c (freadahead): |
| 15 | * lib/freading.c (freading): |
| 16 | * lib/fseeko.c (fseeko): |
| 17 | * lib/stdio-impl.h (_IO_IN_BACKUP) [_IO_EOF_SEEN]: |
| 18 | Define if not already defined. |
| 19 | |
| 20 | Upstream-commit: 4af4a4a71827c0bc5e0ec67af23edef4f15cee8e |
| 21 | Signed-off-by: Kamil Dudka <kdudka@redhat.com> |
| 22 | Upstream-Status: Backport [4af4a4a71827c0bc5e0ec67af23edef4f15cee8e] |
| 23 | --- |
| 24 | gl/lib/fflush.c | 6 +++--- |
| 25 | gl/lib/fpurge.c | 2 +- |
| 26 | gl/lib/freadahead.c | 2 +- |
| 27 | gl/lib/freading.c | 2 +- |
| 28 | gl/lib/fseeko.c | 4 ++-- |
| 29 | gl/lib/stdio-impl.h | 6 ++++++ |
| 30 | 6 files changed, 14 insertions(+), 8 deletions(-) |
| 31 | |
| 32 | Index: findutils-4.6.0/gl/lib/fflush.c |
| 33 | =================================================================== |
| 34 | --- findutils-4.6.0.orig/gl/lib/fflush.c |
| 35 | +++ findutils-4.6.0/gl/lib/fflush.c |
| 36 | @@ -33,7 +33,7 @@ |
| 37 | #undef fflush |
| 38 | |
| 39 | |
| 40 | -#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 41 | +#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 42 | |
| 43 | /* Clear the stream's ungetc buffer, preserving the value of ftello (fp). */ |
| 44 | static void |
| 45 | @@ -72,7 +72,7 @@ clear_ungetc_buffer (FILE *fp) |
| 46 | |
| 47 | #endif |
| 48 | |
| 49 | -#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */) |
| 50 | +#if ! (defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */) |
| 51 | |
| 52 | # if (defined __sferror || defined __DragonFly__ || defined __ANDROID__) && defined __SNPT |
| 53 | /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */ |
| 54 | @@ -148,7 +148,7 @@ rpl_fflush (FILE *stream) |
| 55 | if (stream == NULL || ! freading (stream)) |
| 56 | return fflush (stream); |
| 57 | |
| 58 | -#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 59 | +#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 60 | |
| 61 | clear_ungetc_buffer_preserving_position (stream); |
| 62 | |
| 63 | Index: findutils-4.6.0/gl/lib/fpurge.c |
| 64 | =================================================================== |
| 65 | --- findutils-4.6.0.orig/gl/lib/fpurge.c |
| 66 | +++ findutils-4.6.0/gl/lib/fpurge.c |
| 67 | @@ -62,7 +62,7 @@ fpurge (FILE *fp) |
| 68 | /* Most systems provide FILE as a struct and the necessary bitmask in |
| 69 | <stdio.h>, because they need it for implementing getc() and putc() as |
| 70 | fast macros. */ |
| 71 | -# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 72 | +# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 73 | fp->_IO_read_end = fp->_IO_read_ptr; |
| 74 | fp->_IO_write_ptr = fp->_IO_write_base; |
| 75 | /* Avoid memory leak when there is an active ungetc buffer. */ |
| 76 | Index: findutils-4.6.0/gl/lib/freadahead.c |
| 77 | =================================================================== |
| 78 | --- findutils-4.6.0.orig/gl/lib/freadahead.c |
| 79 | +++ findutils-4.6.0/gl/lib/freadahead.c |
| 80 | @@ -25,7 +25,7 @@ |
| 81 | size_t |
| 82 | freadahead (FILE *fp) |
| 83 | { |
| 84 | -#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 85 | +#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 86 | if (fp->_IO_write_ptr > fp->_IO_write_base) |
| 87 | return 0; |
| 88 | return (fp->_IO_read_end - fp->_IO_read_ptr) |
| 89 | Index: findutils-4.6.0/gl/lib/freading.c |
| 90 | =================================================================== |
| 91 | --- findutils-4.6.0.orig/gl/lib/freading.c |
| 92 | +++ findutils-4.6.0/gl/lib/freading.c |
| 93 | @@ -31,7 +31,7 @@ freading (FILE *fp) |
| 94 | /* Most systems provide FILE as a struct and the necessary bitmask in |
| 95 | <stdio.h>, because they need it for implementing getc() and putc() as |
| 96 | fast macros. */ |
| 97 | -# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 98 | +# if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 99 | return ((fp->_flags & _IO_NO_WRITES) != 0 |
| 100 | || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0 |
| 101 | && fp->_IO_read_base != NULL)); |
| 102 | Index: findutils-4.6.0/gl/lib/fseeko.c |
| 103 | =================================================================== |
| 104 | --- findutils-4.6.0.orig/gl/lib/fseeko.c |
| 105 | +++ findutils-4.6.0/gl/lib/fseeko.c |
| 106 | @@ -47,7 +47,7 @@ fseeko (FILE *fp, off_t offset, int when |
| 107 | #endif |
| 108 | |
| 109 | /* These tests are based on fpurge.c. */ |
| 110 | -#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 111 | +#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 112 | if (fp->_IO_read_end == fp->_IO_read_ptr |
| 113 | && fp->_IO_write_ptr == fp->_IO_write_base |
| 114 | && fp->_IO_save_base == NULL) |
| 115 | @@ -123,7 +123,7 @@ fseeko (FILE *fp, off_t offset, int when |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | -#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 120 | +#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
| 121 | fp->_flags &= ~_IO_EOF_SEEN; |
| 122 | fp->_offset = pos; |
| 123 | #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__ |
| 124 | Index: findutils-4.6.0/gl/lib/stdio-impl.h |
| 125 | =================================================================== |
| 126 | --- findutils-4.6.0.orig/gl/lib/stdio-impl.h |
| 127 | +++ findutils-4.6.0/gl/lib/stdio-impl.h |
| 128 | @@ -18,6 +18,12 @@ |
| 129 | the same implementation of stdio extension API, except that some fields |
| 130 | have different naming conventions, or their access requires some casts. */ |
| 131 | |
| 132 | +/* Glibc 2.28 made _IO_IN_BACKUP private. For now, work around this |
| 133 | + problem by defining it ourselves. FIXME: Do not rely on glibc |
| 134 | + internals. */ |
| 135 | +#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN |
| 136 | +# define _IO_IN_BACKUP 0x100 |
| 137 | +#endif |
| 138 | |
| 139 | /* BSD stdio derived implementations. */ |
| 140 | |