w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 898c2c8ce42f9ea2e74456831c50aa47b9fa7ce4
parent f666fbf536d1f2a6fc4c2288eb8d11d091808576
Author: ukai <ukai>
Date:   Thu, 23 Jan 2003 15:59:24 +0000

[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>

Diffstat:
MChangeLog | 6++++++
Metc.c | 10++++++++--
Mfile.c | 24+++++++++++++++---------
3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -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> * [w3m-dev 03678] Re: config.param is clear when configure -help diff --git a/etc.c b/etc.c @@ -1369,11 +1369,17 @@ open_pipe_rw(FILE ** fr, FILE ** fw) else { if (fr) { close(fdr[1]); - *fr = fdopen(fdr[0], "r"); + if (*fr == stdin) + dup2(fdr[0], 0); + else + *fr = fdopen(fdr[0], "r"); } if (fw) { close(fdw[0]); - *fw = fdopen(fdw[1], "w"); + if (*fw == stdout) + dup2(fdw[1], 1); + else + *fw = fdopen(fdw[1], "w"); } } return pid; diff --git a/file.c b/file.c @@ -7749,6 +7749,7 @@ uncompress_stream(URLFile *uf, char **src) tmpf = tmpfname(TMPF_DFL, ext)->ptr; } + /* child1 -- stdout|f1=uf -> parent */ pid1 = open_pipe_rw(&f1, NULL); if (pid1 < 0) { UFclose(uf); @@ -7757,31 +7758,36 @@ uncompress_stream(URLFile *uf, char **src) if (pid1 == 0) { /* child */ pid_t pid2; - FILE *f2; - dup2(1, 2); /* stderr>&stdout */ - setup_child(TRUE, -1, UFfileno(uf)); - pid2 = open_pipe_rw(NULL, &f2); + FILE *f2 = stdin; + + /* uf -> child2 -- stdout|stdin -> child1 */ + pid2 = open_pipe_rw(&f2, NULL); if (pid2 < 0) { UFclose(uf); exit(1); } - if (pid2 > 0) { + if (pid2 == 0) { + /* child2 */ Str buf = Strnew_size(SAVE_BUF_SIZE); FILE *f = NULL; + + setup_child(TRUE, 2, UFfileno(uf)); if (tmpf) f = fopen(tmpf, "wb"); while (UFread(uf, buf, SAVE_BUF_SIZE)) { - if (Strfputs(buf, f2) < 0) + if (Strfputs(buf, stdout) < 0) break; if (f) Strfputs(buf, f); } - fclose(f2); + UFclose(uf); if (f) fclose(f); exit(0); } - /* child */ + /* child1 */ + dup2(1, 2); /* stderr>&stdout */ + setup_child(TRUE, -1, -1); execlp(expand_cmd, expand_name, NULL); exit(1); } @@ -7792,7 +7798,7 @@ uncompress_stream(URLFile *uf, char **src) uf->scheme = SCM_LOCAL; } UFhalfclose(uf); - uf->stream = newFileStream(f1, (void (*)())fclose); + uf->stream = newFileStream(f1, (void (*)())pclose); } static FILE *