X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fmhparse.c;h=bf65480e08b6c76cb56a79a220eb1f779b6ffca5;hb=d0581ba306a7299113a346f9b4c46ce97bc4cef6;hp=b3b07e48cd859baa03b1ed65f875b1606470de26;hpb=5fbf37ee68e018998ada61eeab73e035b26834b6;p=mmh diff --git a/uip/mhparse.c b/uip/mhparse.c index b3b07e4..bf65480 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -18,11 +18,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - - extern int debugsw; extern int endian; /* mhmisc.c */ @@ -1701,7 +1696,7 @@ static int openBase64(CT ct, char **file) { int bitno, cc, digested; - int fd, len, skip; + int fd, len, skip, own_ct_fp = 0; unsigned long bits; unsigned char value, *b, *b1, *b2, *b3; unsigned char *cp, *ep; @@ -1777,9 +1772,13 @@ openBase64(CT ct, char **file) if ((len = ct->c_end - ct->c_begin) < 0) adios(NULL, "internal error(1)"); - if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) { - content_error(ct->c_file, ct, "unable to open for reading"); - return NOTOK; + if (!ct->c_fp) { + if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) { + content_error(ct->c_file, ct, + "unable to open for reading"); + return NOTOK; + } + own_ct_fp = 1; } if ((digested = ct->c_digested)) @@ -1885,10 +1884,18 @@ self_delimiting: ready_to_go: *file = ce->ce_file; + if (own_ct_fp) { + fclose(ct->c_fp); + ct->c_fp = NULL; + } return fileno(ce->ce_fp); clean_up: free_encoding(ct, 0); + if (own_ct_fp) { + fclose(ct->c_fp); + ct->c_fp = NULL; + } return NOTOK; } @@ -1927,7 +1934,7 @@ InitQuoted(CT ct) static int openQuoted(CT ct, char **file) { - int cc, digested, len, quoted; + int cc, digested, len, quoted, own_ct_fp = 0; unsigned char *cp, *ep; char buffer[BUFSIZ]; unsigned char mask; @@ -1992,18 +1999,16 @@ openQuoted(CT ct, char **file) return NOTOK; } - if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) { - content_error(ce->ce_file, ct, - "unable to fopen for reading/writing"); - return NOTOK; - } - if ((len = ct->c_end - ct->c_begin) < 0) adios(NULL, "internal error(2)"); - if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) { - content_error(ct->c_file, ct, "unable to open for reading"); - return NOTOK; + if (!ct->c_fp) { + if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) { + content_error(ct->c_file, ct, + "unable to open for reading"); + return NOTOK; + } + own_ct_fp = 1; } if ((digested = ct->c_digested)) @@ -2138,10 +2143,18 @@ openQuoted(CT ct, char **file) ready_to_go: *file = ce->ce_file; + if (own_ct_fp) { + fclose(ct->c_fp); + ct->c_fp = NULL; + } return fileno(ce->ce_fp); clean_up: free_encoding(ct, 0); + if (own_ct_fp) { + fclose(ct->c_fp); + ct->c_fp = NULL; + } return NOTOK; } @@ -2164,7 +2177,7 @@ Init7Bit(CT ct) int open7Bit(CT ct, char **file) { - int cc, fd, len; + int cc, fd, len, own_ct_fp = 0; char buffer[BUFSIZ]; /* sbeck -- handle suffixes */ char *cp; @@ -2281,9 +2294,13 @@ open7Bit(CT ct, char **file) if ((len = ct->c_end - ct->c_begin) < 0) adios(NULL, "internal error(3)"); - if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) { - content_error(ct->c_file, ct, "unable to open for reading"); - return NOTOK; + if (!ct->c_fp) { + if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) { + content_error(ct->c_file, ct, + "unable to open for reading"); + return NOTOK; + } + own_ct_fp = 1; } lseek(fd = fileno(ct->c_fp), (off_t) ct->c_begin, SEEK_SET); @@ -2321,10 +2338,18 @@ open7Bit(CT ct, char **file) ready_to_go: *file = ce->ce_file; + if (own_ct_fp) { + fclose(ct->c_fp); + ct->c_fp = NULL; + } return fileno(ce->ce_fp); clean_up: free_encoding(ct, 0); + if (own_ct_fp) { + fclose(ct->c_fp); + ct->c_fp = NULL; + } return NOTOK; } @@ -2724,7 +2749,7 @@ openMail(CT ct, char **file) return NOTOK; vecp = 0; - vec[vecp++] = mhbasename(mailproc); + vec[vecp++] = "mhmail"; vec[vecp++] = e->eb_server; vec[vecp++] = "-subject"; vec[vecp++] = e->eb_subject ? e->eb_subject : "mail-server request"; @@ -2738,9 +2763,9 @@ openMail(CT ct, char **file) return NOTOK; case OK: - execvp(mailproc, vec); + execvp(*vec, vec); fprintf(stderr, "unable to exec "); - perror(mailproc); + perror(*vec); _exit(-1); /* NOTREACHED */