diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2003-01-22 16:10:27 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2003-01-22 16:10:27 +0000 |
commit | b8b4edb15b7c1eca41c6272a197b37574d5c8238 (patch) | |
tree | 6b5680ba64aacb350b972e377e883c37e32909cf /local.c | |
parent | [w3m-dev 03675] x-face (diff) | |
download | w3m-b8b4edb15b7c1eca41c6272a197b37574d5c8238.tar.gz w3m-b8b4edb15b7c1eca41c6272a197b37574d5c8238.zip |
[w3m-dev 03676] cleanup for pipe
* etc.c (open_pipe_rw): added
* file.c (uncompress_stream): rewrite using open_pipe_rw
* image.c (openImgdisplay): rewrite using open_pipe_rw
* local.c (localcgi_popen_rw): deleted
(localcgi_post): rewrite using open_pipe_rw
* proto.h (open_pipe_rw): added
* search.c (migemor): initialized to NULL
(migemow): initialized to NULL
(migemo_pid): initialized to 0
(open_migemo): rewrite using open_pipe_rw
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to '')
-rw-r--r-- | local.c | 67 |
1 files changed, 9 insertions, 58 deletions
@@ -1,4 +1,4 @@ -/* $Id: local.c,v 1.24 2003/01/17 17:07:00 ukai Exp $ */ +/* $Id: local.c,v 1.25 2003/01/22 16:10:28 ukai Exp $ */ #include "fm.h" #include <string.h> #include <stdio.h> @@ -355,60 +355,10 @@ cgi_filename(char *fn, int *status) return fn; } -static pid_t -localcgi_popen_rw(int *p_fdr, int *p_fdw) -{ - int fdr[2], fdw[2]; - pid_t pid; - Str emsg; - - if (pipe(fdr) < 0) { - emsg = Sprintf("localcgi_popen_rw: pipe: %s", strerror(errno)); - goto pipe_err0; - } - if (p_fdw && pipe(fdw) < 0) { - emsg = Sprintf("localcgi_popen_rw: pipe: %s", strerror(errno)); - goto pipe_err1; - } - - flush_tty(); - if ((pid = fork()) < 0) { - emsg = Sprintf("localcgi_popen_rw: fork: %s", strerror(errno)); - goto pipe_err2; - } - else if (!pid) { - close(fdr[0]); - dup2(fdr[1], 1); - if (p_fdw) { - close(fdw[1]); - dup2(fdw[0], 0); - } - setup_child(TRUE, 2, -1); - } - else { - close(fdr[1]); - *p_fdr = fdr[0]; - if (p_fdw) { - close(fdw[0]); - *p_fdw = fdw[1]; - } - } - return pid; - pipe_err2: - close(fdw[0]); - close(fdw[1]); - pipe_err1: - close(fdr[0]); - close(fdr[1]); - pipe_err0: - disp_err_message(emsg->ptr, FALSE); - return (pid_t) - 1; -} - FILE * localcgi_post(char *uri, char *qstr, FormList *request, char *referer) { - int fdr, fdw = -1; + FILE *fr = NULL, *fw = NULL; int status; pid_t pid; char *file; @@ -418,18 +368,19 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer) return NULL; writeLocalCookie(); if (request && request->enctype != FORM_ENCTYPE_MULTIPART) - pid = localcgi_popen_rw(&fdr, &fdw); + pid = open_pipe_rw(&fr, &fw); else - pid = localcgi_popen_rw(&fdr, NULL); + pid = open_pipe_rw(&fr, NULL); if (pid < 0) return NULL; else if (pid) { - if (fdw > 0) { - write(fdw, request->body, request->length); - close(fdw); + if (fw) { + fwrite(request->body, sizeof(char), request->length, fw); + fclose(fw); } - return fdopen(fdr, "r"); + return fr; } + setup_child(TRUE, 2, -1); if (qstr == NULL) set_cgi_environ(uri, file, uri); |