1 Index: lesstif2-0.95.0/lib/Xm-2.1/XpmRdFToI.c
2 ===================================================================
3 --- lesstif2-0.95.0.orig/lib/Xm-2.1/XpmRdFToI.c 2004-11-18 22:00:58.000000000 +0100
4 +++ lesstif2-0.95.0/lib/Xm-2.1/XpmRdFToI.c 2006-07-11 11:13:29.000000000 +0200
12 #ifdef HAVE_SYS_TYPES_H
13 #include <sys/types.h>
15 +#ifdef HAVE_SYS_WAIT_H
16 +#include <sys/wait.h>
18 #ifdef HAVE_SYS_STAT_H
23 else return (XpmFileInvalid); }
25 -#include <sys/stat.h>
26 -#if !defined(NO_ZPIPE) && defined(WIN32)
27 -# define popen _popen
28 -# define pclose _pclose
29 -# if defined(STAT_ZFILE)
32 -# define fstat _fstat
36 LFUNC(OpenReadFile, int, (char *filename, xpmData *mdata));
37 LFUNC(xpmDataClose, void, (xpmData *mdata));
38 @@ -173,90 +167,131 @@
43 - * open the given file to be read as an xpmData which is returned.
46 - FILE *s_popen(char *cmd, const char *type);
48 -# define s_popen popen
49 +/* Do not depend on errno after read_through */
51 +xpmPipeThrough(fd, cmd, arg1, mode)
58 + int status, fds[2], in = 0, out = 1;
62 + if ( pipe(fds) < 0 )
70 + if ( dup2(fds[out], out) < 0 )
73 + if ( dup2(fd, in) < 0 )
81 + execlp(cmd, cmd, arg1, NULL);
90 + /* calling process: wait for first child */
91 + while ( waitpid(pid, &status, 0) < 0 && EINTR == errno )
93 + if ( WIFSIGNALED(status) ||
94 + (WIFEXITED(status) && WEXITSTATUS(status) != 0) )
96 + fp = fdopen(fds[in], mode);
99 + close(fd); /* still open in 2nd child */
110 + * open the given file to be read as an xpmData which is returned.
113 OpenReadFile(filename, mdata)
120 - char *compressfile;
121 - struct stat status;
126 mdata->stream.file = (stdin);
127 mdata->type = XPMFILE;
130 - size_t len = strlen(filename);
133 - filename[len-1] == '/')
134 - return(XpmOpenFailed);
135 - if ((len > 2) && !strcmp(".Z", filename + (len - 2))) {
136 - mdata->type = XPMPIPE;
137 - snprintf(buf, sizeof(buf), "uncompress -c \"%s\"", filename);
138 - if (!(mdata->stream.file = s_popen(buf, "r")))
139 - return (XpmOpenFailed);
141 - } else if ((len > 3) && !strcmp(".gz", filename + (len - 3))) {
142 - mdata->type = XPMPIPE;
143 - snprintf(buf, sizeof(buf), "gunzip -qc \"%s\"", filename);
144 - if (!(mdata->stream.file = s_popen(buf, "r")))
145 - return (XpmOpenFailed);
149 - if (!(compressfile = (char *) XpmMalloc(len + 4)))
150 + int fd = open(filename, O_RDONLY);
151 +#if defined(NO_ZPIPE)
153 + return XpmOpenFailed;
155 + const char* ext = NULL;
157 + ext = strrchr(filename, '.');
158 +#ifdef STAT_ZFILE /* searching for z-files if the given name not found */
161 + size_t len = strlen(filename);
162 + char *compressfile = (char *) XpmMalloc(len + 4);
163 + if ( !compressfile )
164 return (XpmNoMemory);
166 - snprintf(compressfile, len+4, "%s.Z", filename);
167 - if (!stat(compressfile, &status)) {
168 - snprintf(buf, sizeof(buf), "uncompress -c \"%s\"", compressfile);
169 - if (!(mdata->stream.file = s_popen(buf, "r"))) {
170 + strcpy(compressfile, filename);
171 + strcpy(compressfile + len, ext = ".Z");
172 + fd = open(compressfile, O_RDONLY);
175 + strcpy(compressfile + len, ext = ".gz");
176 + fd = open(compressfile, O_RDONLY);
179 XpmFree(compressfile);
180 - return (XpmOpenFailed);
182 - mdata->type = XPMPIPE;
184 - snprintf(compressfile, len+4, "%s.gz", filename);
185 - if (!stat(compressfile, &status)) {
186 - snprintf(buf, sizeof(buf), "gunzip -c \"%s\"", compressfile);
187 - if (!(mdata->stream.file = s_popen(buf, "r"))) {
188 - XpmFree(compressfile);
189 - return (XpmOpenFailed);
191 - mdata->type = XPMPIPE;
195 - if (!(mdata->stream.file = fopen(filename, "r"))) {
196 -#if !defined(NO_ZPIPE) && defined(STAT_ZFILE)
197 - XpmFree(compressfile);
199 - return (XpmOpenFailed);
201 - mdata->type = XPMFILE;
204 + return XpmOpenFailed;
207 XpmFree(compressfile);
211 + if ( ext && !strcmp(ext, ".Z") )
213 + mdata->type = XPMPIPE;
214 + mdata->stream.file = xpmPipeThrough(fd, "uncompress", "-c", "r");
216 + else if ( ext && !strcmp(ext, ".gz") )
218 + mdata->type = XPMPIPE;
219 + mdata->stream.file = xpmPipeThrough(fd, "gunzip", "-qc", "r");
222 +#endif /* z-files */
224 + mdata->type = XPMFILE;
225 + mdata->stream.file = fdopen(fd, "r");
227 + if (!mdata->stream.file)
230 + return (XpmOpenFailed);
233 mdata->CommentLength = 0;
239 - switch (mdata->type) {
241 - if (mdata->stream.file != (stdin))
242 - fclose(mdata->stream.file);
246 + if (mdata->stream.file != (stdin))
247 fclose(mdata->stream.file);
252 Index: lesstif2-0.95.0/lib/Xm-2.1/XpmWrFFrI.c
253 ===================================================================
254 --- lesstif2-0.95.0.orig/lib/Xm-2.1/XpmWrFFrI.c 2005-04-13 20:03:27.000000000 +0200
255 +++ lesstif2-0.95.0/lib/Xm-2.1/XpmWrFFrI.c 2006-07-11 11:13:29.000000000 +0200
263 #ifdef HAVE_SYS_TYPES_H
264 #include <sys/types.h>
266 +#ifdef HAVE_SYS_WAIT_H
267 +#include <sys/wait.h>
269 #ifdef HAVE_SYS_STAT_H
270 #include <sys/stat.h>
273 else return (XpmFileInvalid); }
276 -#if !defined(NO_ZPIPE) && defined(WIN32)
277 -# define popen _popen
278 -# define pclose _pclose
281 /* MS Windows define a function called WriteFile @#%#&!!! */
282 LFUNC(xpmWriteFile, int, (FILE *file, XpmImage *image, char *name,
284 @@ -354,58 +353,48 @@
285 fprintf(file, ",\n\"XPMENDEXT\"");
290 +FUNC(xpmPipeThrough, FILE*, (int fd,
293 + const char* mode));
297 * open the given file to be written as an xpmData which is returned
300 - FILE *s_popen(char *cmd, const char *type);
302 -# define s_popen popen
305 OpenWriteFile(filename, mdata)
315 mdata->stream.file = (stdout);
316 mdata->type = XPMFILE;
319 - size_t len = strlen(filename);
322 - filename[0] == '/' ||
323 - strstr(filename, "../") != NULL ||
324 - filename[len-1] == '/')
325 - return(XpmOpenFailed);
329 + int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
331 + return(XpmOpenFailed);
333 + len = strlen(filename);
334 if (len > 2 && !strcmp(".Z", filename + (len - 2))) {
335 - snprintf(buf, sizeof(buf), "compress > \"%s\"", filename);
336 - if (!(mdata->stream.file = s_popen(buf, "w")))
337 - return (XpmOpenFailed);
339 + mdata->stream.file = xpmPipeThrough(fd, "compress", NULL, "w");
340 mdata->type = XPMPIPE;
341 } else if (len > 3 && !strcmp(".gz", filename + (len - 3))) {
342 - snprintf(buf, sizeof(buf), "gzip -q > \"%s\"", filename);
343 - if (!(mdata->stream.file = s_popen(buf, "w")))
344 - return (XpmOpenFailed);
346 + mdata->stream.file = xpmPipeThrough(fd, "gzip", "-q", "w");
347 mdata->type = XPMPIPE;
351 - if (!(mdata->stream.file = fopen(filename, "w")))
352 - return (XpmOpenFailed);
355 + mdata->stream.file = fdopen(fd, "w");
356 mdata->type = XPMFILE;
360 + if (!mdata->stream.file)
361 + return (XpmOpenFailed);
369 - switch (mdata->type) {
371 - if (mdata->stream.file != (stdout))
372 - fclose(mdata->stream.file);
376 + if (mdata->stream.file != (stdout))
377 fclose(mdata->stream.file);