blob: 41bd220badab95ce82f13d8a7cc1f212affabc30 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001From 20e1d8a9481dc13dd1d4d168b90e0ed2ff097b98 Mon Sep 17 00:00:00 2001
2From: Jussi Kukkonen <jussi.kukkonen@intel.com>
3Date: Thu, 6 Aug 2015 14:29:57 +0300
4Subject: [PATCH] texinfo-4.12-zlib
5
6Upstream-Status: Pending
7---
8 install-info/Makefile.in | 2 +-
9 install-info/install-info.c | 67 +++++++++++++++++++++++++++------------------
10 2 files changed, 42 insertions(+), 27 deletions(-)
11
12diff --git a/install-info/Makefile.in b/install-info/Makefile.in
13index ad73abb..eaa2153 100644
14--- a/install-info/Makefile.in
15+++ b/install-info/Makefile.in
16@@ -241,7 +241,7 @@ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)"
17 PROGRAMS = $(bin_PROGRAMS)
18 am_ginstall_info_OBJECTS = install-info.$(OBJEXT)
19 ginstall_info_OBJECTS = $(am_ginstall_info_OBJECTS)
20-ginstall_info_LDADD = $(LDADD)
21+ginstall_info_LDADD = $(LDADD) -lz
22 am__DEPENDENCIES_1 =
23 ginstall_info_DEPENDENCIES = $(top_builddir)/gnulib/lib/libgnu.a \
24 $(am__DEPENDENCIES_1)
25diff --git a/install-info/install-info.c b/install-info/install-info.c
26index b454c15..4e39122 100644
27--- a/install-info/install-info.c
28+++ b/install-info/install-info.c
29@@ -22,6 +22,7 @@
30 #include <getopt.h>
31 #include <regex.h>
32 #include <argz.h>
33+#include <zlib.h>
34
35 #define TAB_WIDTH 8
36
37@@ -684,15 +685,15 @@ The first time you invoke Info you start off looking at this node.\n\
38
39 Return either stdin reading the file, or a non-stdin pipe reading
40 the output of the compression program. */
41-FILE *
42+void *
43 open_possibly_compressed_file (char *filename,
44 void (*create_callback) (char *),
45- char **opened_filename, char **compression_program)
46+ char **opened_filename, char **compression_program, int *is_pipe)
47 {
48 char *local_opened_filename, *local_compression_program;
49 int nread;
50 char data[13];
51- FILE *f;
52+ gzFile *f;
53
54 /* We let them pass NULL if they don't want this info, but it's easier
55 to always determine it. */
56@@ -700,48 +701,48 @@ open_possibly_compressed_file (char *filename,
57 opened_filename = &local_opened_filename;
58
59 *opened_filename = filename;
60- f = fopen (*opened_filename, FOPEN_RBIN);
61+ f = gzopen (*opened_filename, FOPEN_RBIN);
62 if (!f)
63 {
64 *opened_filename = concat (filename, ".gz", "");
65- f = fopen (*opened_filename, FOPEN_RBIN);
66+ f = gzopen (*opened_filename, FOPEN_RBIN);
67 }
68 if (!f)
69 {
70 free (*opened_filename);
71 *opened_filename = concat (filename, ".xz", "");
72- f = fopen (*opened_filename, FOPEN_RBIN);
73+ f = gzopen (*opened_filename, FOPEN_RBIN);
74 }
75 if (!f)
76 {
77 free (*opened_filename);
78 *opened_filename = concat (filename, ".bz2", "");
79- f = fopen (*opened_filename, FOPEN_RBIN);
80+ f = gzopen (*opened_filename, FOPEN_RBIN);
81 }
82 if (!f)
83 {
84 free (*opened_filename);
85 *opened_filename = concat (filename, ".lz", "");
86- f = fopen (*opened_filename, FOPEN_RBIN);
87+ f = gzopen (*opened_filename, FOPEN_RBIN);
88 }
89 if (!f)
90 {
91 free (*opened_filename);
92 *opened_filename = concat (filename, ".lzma", "");
93- f = fopen (*opened_filename, FOPEN_RBIN);
94+ f = gzopen (*opened_filename, FOPEN_RBIN);
95 }
96 #ifdef __MSDOS__
97 if (!f)
98 {
99 free (*opened_filename);
100 *opened_filename = concat (filename, ".igz", "");
101- f = fopen (*opened_filename, FOPEN_RBIN);
102+ f = gzopen (*opened_filename, FOPEN_RBIN);
103 }
104 if (!f)
105 {
106 free (*opened_filename);
107 *opened_filename = concat (filename, ".inz", "");
108- f = fopen (*opened_filename, FOPEN_RBIN);
109+ f = gzopen (*opened_filename, FOPEN_RBIN);
110 }
111 #endif /* __MSDOS__ */
112 if (!f)
113@@ -757,7 +758,7 @@ open_possibly_compressed_file (char *filename,
114 (*create_callback) (filename);
115
116 /* And try opening it again. */
117- f = fopen (*opened_filename, FOPEN_RBIN);
118+ f = gzopen (*opened_filename, FOPEN_RBIN);
119 if (!f)
120 return 0;
121 }
122@@ -767,12 +768,12 @@ open_possibly_compressed_file (char *filename,
123
124 /* Read first few bytes of file rather than relying on the filename.
125 If the file is shorter than this it can't be usable anyway. */
126- nread = fread (data, sizeof (data), 1, f);
127- if (nread != 1)
128+ nread = gzread (f, data, sizeof (data));
129+ if (nread != sizeof (data))
130 {
131 /* Empty files don't set errno. Calling code can check for
132 this, so make sure errno == 0 just in case it isn't already. */
133- if (nread == 0)
134+ if (nread >= 0)
135 errno = 0;
136 return 0;
137 }
138@@ -838,35 +839,40 @@ open_possibly_compressed_file (char *filename,
139 *compression_program = NULL;
140
141 /* Seek back over the magic bytes. */
142- if (fseek (f, 0, 0) < 0)
143+ if (gzseek (f, 0, SEEK_SET) == -1)
144 return 0;
145
146 if (*compression_program)
147 { /* It's compressed, so open a pipe. */
148+ FILE *p;
149 char *command = concat (*compression_program, " -d", "");
150
151- if (fclose (f) < 0)
152+ if (gzclose (f) < 0)
153 return 0;
154- f = freopen (*opened_filename, FOPEN_RBIN, stdin);
155- if (!f)
156+ p = freopen (*opened_filename, FOPEN_RBIN, stdin);
157+ if (!p)
158 return 0;
159- f = popen (command, "r");
160- if (!f)
161+ p = popen (command, "r");
162+ if (!p)
163 {
164 /* Used for error message in calling code. */
165 *opened_filename = command;
166 return 0;
167 }
168+ else
169+ *is_pipe = 1;
170+ return p;
171 }
172 else
173 {
174-#if O_BINARY
175+#if 0 && O_BINARY
176 /* Since this is a text file, and we opened it in binary mode,
177 switch back to text mode. */
178 f = freopen (*opened_filename, "r", f);
179 if (! f)
180 return 0;
181 #endif
182+ *is_pipe = 0;
183 }
184
185 return f;
186@@ -885,7 +891,8 @@ readfile (char *filename, int *sizep,
187 void (*create_callback) (char *), char **opened_filename,
188 char **compression_program)
189 {
190- FILE *f;
191+ void *f;
192+ int pipe_p;
193 int filled = 0;
194 int data_size = 8192;
195 char *data = xmalloc (data_size);
196@@ -893,14 +900,20 @@ readfile (char *filename, int *sizep,
197 /* If they passed the space for the file name to return, use it. */
198 f = open_possibly_compressed_file (filename, create_callback,
199 opened_filename,
200- compression_program);
201+ compression_program,
202+ &pipe_p);
203
204 if (!f)
205 return 0;
206
207 for (;;)
208 {
209- int nread = fread (data + filled, 1, data_size - filled, f);
210+ int nread;
211+
212+ if (pipe_p)
213+ nread = fread (data + filled, 1, data_size - filled, f);
214+ else
215+ nread = gzread (f, data + filled, data_size - filled);
216 if (nread < 0)
217 return 0;
218 if (nread == 0)
219@@ -919,8 +932,10 @@ readfile (char *filename, int *sizep,
220 /* We need to close the stream, since on some systems the pipe created
221 by popen is simulated by a temporary file which only gets removed
222 inside pclose. */
223- if (f != stdin)
224+ if (pipe_p)
225 pclose (f);
226+ else
227+ gzclose (f);
228
229 *sizep = filled;
230 return data;
231--
2322.1.4
233