Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | From 3d3b66cf398853c666e724c3dbcc37d53a2240d5 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | From: Edwin Plauchu <edwin.plauchu.camacho@intel.com> |
| 3 | Date: Tue, 29 Nov 2016 12:27:17 -0600 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4 | Subject: [PATCH] texinfo-4.12-zlib |
| 5 | |
| 6 | Upstream-Status: Pending |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | |
| 8 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
| 9 | Signed-off-by: Edwin Plauchu <edwin.plauchu.camacho@intel.com> |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 10 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | --- |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 12 | install-info/Makefile.in | 2 +- |
| 13 | install-info/install-info.c | 79 ++++++++++++++++++++++--------------- |
| 14 | 2 files changed, 48 insertions(+), 33 deletions(-) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
| 16 | diff --git a/install-info/Makefile.in b/install-info/Makefile.in |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 17 | index c924509..746df05 100644 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | --- a/install-info/Makefile.in |
| 19 | +++ b/install-info/Makefile.in |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 20 | @@ -218,7 +218,7 @@ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | PROGRAMS = $(bin_PROGRAMS) |
| 22 | am_ginstall_info_OBJECTS = install-info.$(OBJEXT) |
| 23 | ginstall_info_OBJECTS = $(am_ginstall_info_OBJECTS) |
| 24 | -ginstall_info_LDADD = $(LDADD) |
| 25 | +ginstall_info_LDADD = $(LDADD) -lz |
| 26 | am__DEPENDENCIES_1 = |
| 27 | ginstall_info_DEPENDENCIES = $(top_builddir)/gnulib/lib/libgnu.a \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 28 | $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | diff --git a/install-info/install-info.c b/install-info/install-info.c |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 30 | index 21f4fe3..a7aba82 100644 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | --- a/install-info/install-info.c |
| 32 | +++ b/install-info/install-info.c |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 33 | @@ -19,6 +19,7 @@ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | #include <getopt.h> |
| 35 | #include <regex.h> |
| 36 | #include <argz.h> |
| 37 | +#include <zlib.h> |
| 38 | |
| 39 | #define TAB_WIDTH 8 |
| 40 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 41 | @@ -681,15 +682,15 @@ The first time you invoke Info you start off looking at this node.\n\ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | |
| 43 | Return either stdin reading the file, or a non-stdin pipe reading |
| 44 | the output of the compression program. */ |
| 45 | -FILE * |
| 46 | +void * |
| 47 | open_possibly_compressed_file (char *filename, |
| 48 | void (*create_callback) (char *), |
| 49 | - char **opened_filename, char **compression_program) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 50 | + char **opened_filename, char **compression_program, int *is_pipe) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | { |
| 52 | char *local_opened_filename, *local_compression_program; |
| 53 | int nread; |
| 54 | char data[13]; |
| 55 | - FILE *f; |
| 56 | + gzFile *f; |
| 57 | |
| 58 | /* We let them pass NULL if they don't want this info, but it's easier |
| 59 | to always determine it. */ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 60 | @@ -697,48 +698,48 @@ open_possibly_compressed_file (char *filename, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | opened_filename = &local_opened_filename; |
| 62 | |
| 63 | *opened_filename = filename; |
| 64 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 65 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 66 | if (!f) |
| 67 | { |
| 68 | *opened_filename = concat (filename, ".gz", ""); |
| 69 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 70 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 71 | } |
| 72 | if (!f) |
| 73 | { |
| 74 | free (*opened_filename); |
| 75 | *opened_filename = concat (filename, ".xz", ""); |
| 76 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 77 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 78 | } |
| 79 | if (!f) |
| 80 | { |
| 81 | free (*opened_filename); |
| 82 | *opened_filename = concat (filename, ".bz2", ""); |
| 83 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 84 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 85 | } |
| 86 | if (!f) |
| 87 | { |
| 88 | free (*opened_filename); |
| 89 | *opened_filename = concat (filename, ".lz", ""); |
| 90 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 91 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 92 | } |
| 93 | if (!f) |
| 94 | { |
| 95 | free (*opened_filename); |
| 96 | *opened_filename = concat (filename, ".lzma", ""); |
| 97 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 98 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 99 | } |
| 100 | #ifdef __MSDOS__ |
| 101 | if (!f) |
| 102 | { |
| 103 | free (*opened_filename); |
| 104 | *opened_filename = concat (filename, ".igz", ""); |
| 105 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 106 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 107 | } |
| 108 | if (!f) |
| 109 | { |
| 110 | free (*opened_filename); |
| 111 | *opened_filename = concat (filename, ".inz", ""); |
| 112 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 113 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 114 | } |
| 115 | #endif /* __MSDOS__ */ |
| 116 | if (!f) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 117 | @@ -754,7 +755,7 @@ open_possibly_compressed_file (char *filename, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | (*create_callback) (filename); |
| 119 | |
| 120 | /* And try opening it again. */ |
| 121 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 122 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 123 | if (!f) |
| 124 | return 0; |
| 125 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 126 | @@ -764,26 +765,26 @@ open_possibly_compressed_file (char *filename, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | |
| 128 | /* Read first few bytes of file rather than relying on the filename. |
| 129 | If the file is shorter than this it can't be usable anyway. */ |
| 130 | - nread = fread (data, sizeof (data), 1, f); |
| 131 | - if (nread != 1) |
| 132 | + nread = gzread (f, data, sizeof (data)); |
| 133 | + if (nread != sizeof (data)) |
| 134 | { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | - if (nread == 0) |
| 136 | + if (nread >= 0) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | { |
| 138 | /* Try to create the file if its empty. */ |
| 139 | - if (feof (f) && create_callback) |
| 140 | + if (gzeof(f) && create_callback) |
| 141 | { |
| 142 | - if (fclose (f) != 0) |
| 143 | + if (gzclose(f) != 0) |
| 144 | return 0; /* unknown error closing file */ |
| 145 | |
| 146 | - if (remove (filename) != 0) |
| 147 | + if (remove(filename) != 0) |
| 148 | return 0; /* unknown error deleting file */ |
| 149 | |
| 150 | (*create_callback) (filename); |
| 151 | - f = fopen (*opened_filename, FOPEN_RBIN); |
| 152 | + f = gzopen (*opened_filename, FOPEN_RBIN); |
| 153 | if (!f) |
| 154 | return 0; |
| 155 | - nread = fread (data, sizeof (data), 1, f); |
| 156 | - if (nread == 0) |
| 157 | + nread = gzread(f, data, sizeof (data)); |
| 158 | + if (nread >= 0) |
| 159 | return 0; |
| 160 | goto determine_file_type; /* success */ |
| 161 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 162 | @@ -854,35 +855,40 @@ determine_file_type: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 | *compression_program = NULL; |
| 164 | |
| 165 | /* Seek back over the magic bytes. */ |
| 166 | - if (fseek (f, 0, 0) < 0) |
| 167 | + if (gzseek (f, 0, SEEK_SET) == -1) |
| 168 | return 0; |
| 169 | |
| 170 | if (*compression_program) |
| 171 | { /* It's compressed, so open a pipe. */ |
| 172 | + FILE *p; |
| 173 | char *command = concat (*compression_program, " -d", ""); |
| 174 | |
| 175 | - if (fclose (f) < 0) |
| 176 | + if (gzclose (f) < 0) |
| 177 | return 0; |
| 178 | - f = freopen (*opened_filename, FOPEN_RBIN, stdin); |
| 179 | - if (!f) |
| 180 | + p = freopen (*opened_filename, FOPEN_RBIN, stdin); |
| 181 | + if (!p) |
| 182 | return 0; |
| 183 | - f = popen (command, "r"); |
| 184 | - if (!f) |
| 185 | + p = popen (command, "r"); |
| 186 | + if (!p) |
| 187 | { |
| 188 | /* Used for error message in calling code. */ |
| 189 | *opened_filename = command; |
| 190 | return 0; |
| 191 | } |
| 192 | + else |
| 193 | + *is_pipe = 1; |
| 194 | + return p; |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | -#if O_BINARY |
| 199 | +#if 0 && O_BINARY |
| 200 | /* Since this is a text file, and we opened it in binary mode, |
| 201 | switch back to text mode. */ |
| 202 | f = freopen (*opened_filename, "r", f); |
| 203 | if (! f) |
| 204 | return 0; |
| 205 | #endif |
| 206 | + *is_pipe = 0; |
| 207 | } |
| 208 | |
| 209 | return f; |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 210 | @@ -901,7 +907,8 @@ readfile (char *filename, int *sizep, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | void (*create_callback) (char *), char **opened_filename, |
| 212 | char **compression_program) |
| 213 | { |
| 214 | - FILE *f; |
| 215 | + void *f; |
| 216 | + int pipe_p; |
| 217 | int filled = 0; |
| 218 | int data_size = 8192; |
| 219 | char *data = xmalloc (data_size); |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 220 | @@ -909,14 +916,20 @@ readfile (char *filename, int *sizep, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 221 | /* If they passed the space for the file name to return, use it. */ |
| 222 | f = open_possibly_compressed_file (filename, create_callback, |
| 223 | opened_filename, |
| 224 | - compression_program); |
| 225 | + compression_program, |
| 226 | + &pipe_p); |
| 227 | |
| 228 | if (!f) |
| 229 | return 0; |
| 230 | |
| 231 | for (;;) |
| 232 | { |
| 233 | - int nread = fread (data + filled, 1, data_size - filled, f); |
| 234 | + int nread; |
| 235 | + |
| 236 | + if (pipe_p) |
| 237 | + nread = fread (data + filled, 1, data_size - filled, f); |
| 238 | + else |
| 239 | + nread = gzread (f, data + filled, data_size - filled); |
| 240 | if (nread < 0) |
| 241 | return 0; |
| 242 | if (nread == 0) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 243 | @@ -935,8 +948,10 @@ readfile (char *filename, int *sizep, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | /* We need to close the stream, since on some systems the pipe created |
| 245 | by popen is simulated by a temporary file which only gets removed |
| 246 | inside pclose. */ |
| 247 | - if (f != stdin) |
| 248 | + if (pipe_p) |
| 249 | pclose (f); |
| 250 | + else |
| 251 | + gzclose (f); |
| 252 | |
| 253 | *sizep = filled; |
| 254 | return data; |