X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fmhbuild.c;h=fbe2b2c6c5a86fe1efac1542c6b77fab661cf533;hp=cfe776fe9c816741b37eac374bdd4539726352f0;hb=2f689a1cb907a5de04e6d39ffd217a69af3216c7;hpb=1bb1f6c3f38b05060bf699ea2743f7386889bf63 diff --git a/uip/mhbuild.c b/uip/mhbuild.c index cfe776f..fbe2b2c 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -74,7 +74,6 @@ static struct swit switches[] = { /* mhbuildsbr.c */ -extern int checksw; extern char *tmp; /* directory to place temp files */ /* mhcachesbr.c */ @@ -100,10 +99,12 @@ static int unlink_infile = 0; static char outfile[BUFSIZ]; static int unlink_outfile = 0; +static void unlink_done (int) NORETURN; /* mhbuildsbr.c */ CT build_mime (char *); int output_message (CT, char *); +int output_message_fp (CT, FILE *, char*); /* mhlistsbr.c */ int list_all_messages (CT *, int, int, int, int); @@ -124,7 +125,10 @@ main (int argc, char **argv) char buffer[BUFSIZ], *compfile = NULL; char **argp, **arguments; CT ct, cts[2]; - FILE *fp; + FILE *fp = NULL; + FILE *fp_out = NULL; + + done=unlink_done; #ifdef LOCALE setlocale(LC_ALL, ""); @@ -303,11 +307,8 @@ main (int argc, char **argv) * Process the composition file from standard input. */ if (compfile[0] == '-' && compfile[1] == '\0') { - /* copy standard input to temporary file */ - strncpy (infile, m_scratch ("", invo_name), sizeof(infile)); - if ((fp = fopen (infile, "w")) == NULL) - adios (infile, "unable to open"); + strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile)); while (fgets (buffer, BUFSIZ, stdin)) fputs (buffer, fp); fclose (fp); @@ -319,11 +320,12 @@ main (int argc, char **argv) cts[1] = NULL; /* output MIME message to this temporary file */ - strncpy (outfile, m_scratch ("", invo_name), sizeof(outfile)); + strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile)); unlink_outfile = 1; /* output the message */ - output_message (ct, outfile); + output_message_fp (ct, fp_out, outfile); + fclose(fp_out); /* output the temp file to standard output */ if ((fp = fopen (outfile, "r")) == NULL) @@ -352,11 +354,13 @@ main (int argc, char **argv) cts[1] = NULL; /* output MIME message to this temporary file */ - strncpy (outfile, m_scratch (compfile, invo_name), sizeof(outfile)); + strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out), + sizeof(outfile)); unlink_outfile = 1; /* output the message */ - output_message (ct, outfile); + output_message_fp (ct, fp_out, outfile); + fclose(fp_out); /* * List the message info @@ -366,24 +370,26 @@ main (int argc, char **argv) /* Rename composition draft */ snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile)); - if (rename (compfile, buffer) == NOTOK) - adios (compfile, "unable to rename %s to", buffer); + if (rename (compfile, buffer) == NOTOK) { + adios (compfile, "unable to rename comp draft %s to", buffer); + } /* Rename output file to take its place */ if (rename (outfile, compfile) == NOTOK) { - advise (outfile, "unable to rename %s to", compfile); + advise (outfile, "unable to rename output %s to", compfile); rename (buffer, compfile); done (1); } unlink_outfile = 0; free_content (ct); - return done (0); + done (0); + return 1; } -int -done (int status) +static void +unlink_done (int status) { /* * Check if we need to remove stray @@ -395,5 +401,4 @@ done (int status) unlink (outfile); exit (status); - return 1; /* dead code to satisfy the compiler */ }