[w3m-dev 03679] Re: cleanup for pipe

* etc.c (open_pipe_rw): check stdin, stdout
* file.c (uncompress_stream): rewrite
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2003-01-23 15:59:24 +00:00
parent a0300c84b8
commit fb759b572b
3 changed files with 32 additions and 14 deletions
+7 -1
View File
@@ -1,3 +1,9 @@
2003-01-24 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 03679] Re: cleanup for pipe
* etc.c (open_pipe_rw): check stdin, stdout
* file.c (uncompress_stream): rewrite
2003-01-23 Fumitoshi UKAI <ukai@debian.or.jp> 2003-01-23 Fumitoshi UKAI <ukai@debian.or.jp>
* [w3m-dev 03678] Re: config.param is clear when configure -help * [w3m-dev 03678] Re: config.param is clear when configure -help
@@ -6715,4 +6721,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1 * release-0-2-1
* import w3m-0.2.1 * import w3m-0.2.1
$Id: ChangeLog,v 1.705 2003/01/22 16:36:11 ukai Exp $ $Id: ChangeLog,v 1.706 2003/01/23 15:59:24 ukai Exp $
+7 -1
View File
@@ -1,4 +1,4 @@
/* $Id: etc.c,v 1.54 2003/01/22 16:11:03 ukai Exp $ */ /* $Id: etc.c,v 1.55 2003/01/23 15:59:25 ukai Exp $ */
#include "fm.h" #include "fm.h"
#include <pwd.h> #include <pwd.h>
#include "myctype.h" #include "myctype.h"
@@ -1369,10 +1369,16 @@ open_pipe_rw(FILE ** fr, FILE ** fw)
else { else {
if (fr) { if (fr) {
close(fdr[1]); close(fdr[1]);
if (*fr == stdin)
dup2(fdr[0], 0);
else
*fr = fdopen(fdr[0], "r"); *fr = fdopen(fdr[0], "r");
} }
if (fw) { if (fw) {
close(fdw[0]); close(fdw[0]);
if (*fw == stdout)
dup2(fdw[1], 1);
else
*fw = fdopen(fdw[1], "w"); *fw = fdopen(fdw[1], "w");
} }
} }
+16 -10
View File
@@ -1,4 +1,4 @@
/* $Id: file.c,v 1.200 2003/01/22 16:16:20 ukai Exp $ */ /* $Id: file.c,v 1.201 2003/01/23 15:59:27 ukai Exp $ */
#include "fm.h" #include "fm.h"
#include <sys/types.h> #include <sys/types.h>
#include "myctype.h" #include "myctype.h"
@@ -7749,6 +7749,7 @@ uncompress_stream(URLFile *uf, char **src)
tmpf = tmpfname(TMPF_DFL, ext)->ptr; tmpf = tmpfname(TMPF_DFL, ext)->ptr;
} }
/* child1 -- stdout|f1=uf -> parent */
pid1 = open_pipe_rw(&f1, NULL); pid1 = open_pipe_rw(&f1, NULL);
if (pid1 < 0) { if (pid1 < 0) {
UFclose(uf); UFclose(uf);
@@ -7757,31 +7758,36 @@ uncompress_stream(URLFile *uf, char **src)
if (pid1 == 0) { if (pid1 == 0) {
/* child */ /* child */
pid_t pid2; pid_t pid2;
FILE *f2; FILE *f2 = stdin;
dup2(1, 2); /* stderr>&stdout */
setup_child(TRUE, -1, UFfileno(uf)); /* uf -> child2 -- stdout|stdin -> child1 */
pid2 = open_pipe_rw(NULL, &f2); pid2 = open_pipe_rw(&f2, NULL);
if (pid2 < 0) { if (pid2 < 0) {
UFclose(uf); UFclose(uf);
exit(1); exit(1);
} }
if (pid2 > 0) { if (pid2 == 0) {
/* child2 */
Str buf = Strnew_size(SAVE_BUF_SIZE); Str buf = Strnew_size(SAVE_BUF_SIZE);
FILE *f = NULL; FILE *f = NULL;
setup_child(TRUE, 2, UFfileno(uf));
if (tmpf) if (tmpf)
f = fopen(tmpf, "wb"); f = fopen(tmpf, "wb");
while (UFread(uf, buf, SAVE_BUF_SIZE)) { while (UFread(uf, buf, SAVE_BUF_SIZE)) {
if (Strfputs(buf, f2) < 0) if (Strfputs(buf, stdout) < 0)
break; break;
if (f) if (f)
Strfputs(buf, f); Strfputs(buf, f);
} }
fclose(f2); UFclose(uf);
if (f) if (f)
fclose(f); fclose(f);
exit(0); exit(0);
} }
/* child */ /* child1 */
dup2(1, 2); /* stderr>&stdout */
setup_child(TRUE, -1, -1);
execlp(expand_cmd, expand_name, NULL); execlp(expand_cmd, expand_name, NULL);
exit(1); exit(1);
} }
@@ -7792,7 +7798,7 @@ uncompress_stream(URLFile *uf, char **src)
uf->scheme = SCM_LOCAL; uf->scheme = SCM_LOCAL;
} }
UFhalfclose(uf); UFhalfclose(uf);
uf->stream = newFileStream(f1, (void (*)())fclose); uf->stream = newFileStream(f1, (void (*)())pclose);
} }
static FILE * static FILE *