/*
* distsbr.c -- routines to do additional "dist-style" processing
*
- * $Id$
- *
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
#include <h/mh.h>
#include <fcntl.h>
+#include <h/utils.h>
static int hdrfd = NOTOK;
static int txtfd = NOTOK;
distout (char *drft, char *msgnam, char *backup)
{
int state;
- register char *dp, *resent;
+ register unsigned char *dp;
+ register char *resent;
char name[NAMESZ], buffer[BUFSIZ];
register FILE *ifp, *ofp;
int state, out;
char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
register FILE *ifp, *ofp;
+ char *cp = NULL;
if (hdrfd != NOTOK)
close (hdrfd), hdrfd = NOTOK;
if ((ifp = fopen (msgnam, "r")) == NULL)
adios (msgnam, "unable to open message");
- strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
- if ((hdrfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
- adios (tmpfil, "unable to re-open temporary file");
+ cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
+ if (cp == NULL) {
+ adios("distsbr", "unable to create temporary file");
+ }
+ fchmod(hdrfd, 0600);
+ strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup (hdrfd)) == NOTOK
|| (ofp = fdopen (out, "w")) == NULL)
adios (NULL, "no file descriptors -- you lose big");
case BODYEOF:
fclose (ofp);
- strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
- if ((txtfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
- adios (tmpfil, "unable to open temporary file");
+ cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
+ if (cp == NULL) {
+ adios("distsbr", "unable to create temporary file");
+ }
+ fchmod(txtfd, 0600);
+ strncpy (tmpfil, cp, sizeof(tmpfil));
if ((out = dup (txtfd)) == NOTOK
|| (ofp = fdopen (out, "w")) == NULL)
adios (NULL, "no file descriptors -- you lose big");