Attached are the changes I have currently done in my development
environment. The changes also include minor mods to deal
with "may be uninitialized" warnings from gcc.
I added a new file, sbr/m_mktemp.c, to include the new functions for
replacing m_scratch() and m_tmpfil().
The goal was to minimize the amount of re-coding, so the new functions
attempt to provide the basic capabilities of the older functions,
but using mkstemp() under the hood vs mktemp(). It seems the much
code has a heavy reliance on being able to access the actual pathnames
of temporary files vs just having an open handle to it.
Index: h/prototypes.h
===================================================================
RCS file: /cvsroot/nmh/nmh/h/prototypes.h,v
retrieving revision 1.26
diff -u -r1.26 prototypes.h
--- h/prototypes.h 16 Jan 2009 02:28:54 -0000 1.26
+++ h/prototypes.h 2 Feb 2010 19:36:04 -0000
@@ -81,6 +81,8 @@
int m_putenv (char *, char *);
char *m_scratch (char *, char *);
char *m_tmpfil (char *);
+char *m_mktemp(const char *, int *, FILE **);
+char *m_mktemp2(const char *, const char *, int *, FILE **);
void m_unknown(FILE *);
int makedir (char *);
char *nmh_getpass(const char *);
Index: sbr/Makefile.in
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/Makefile.in,v
retrieving revision 1.28
diff -u -r1.28 Makefile.in
--- sbr/Makefile.in 17 Jan 2009 16:47:30 -0000 1.28
+++ sbr/Makefile.in 2 Feb 2010 19:36:04 -0000
@@ -78,7 +78,7 @@
seq_setprev.c seq_setunseen.c showfile.c signals.c \
smatch.c snprintb.c ssequal.c strcasecmp.c \
strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c \
- m_msgdef.c mf.c utils.c
+ m_msgdef.c mf.c utils.c m_mktemp.c
# source for compatibility functions
COMPAT = memmove.c snprintf.c strdup.c strerror.c
Index: sbr/fmt_rfc2047.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/fmt_rfc2047.c,v
retrieving revision 1.9
diff -u -r1.9 fmt_rfc2047.c
--- sbr/fmt_rfc2047.c 9 Mar 2006 19:51:13 -0000 1.9
+++ sbr/fmt_rfc2047.c 2 Feb 2010 19:36:05 -0000
@@ -71,7 +71,7 @@
int whitespace = 0; /* how much whitespace between
encodings? */
#ifdef HAVE_ICONV
int use_iconv = 0; /* are we converting encoding with iconv? */
- iconv_t cd;
+ iconv_t cd = NULL;
int fromutf8 = 0;
char *saveq, *convbuf = NULL;
size_t savedstlen;
Index: sbr/fmt_scan.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/fmt_scan.c,v
retrieving revision 1.25
diff -u -r1.25 fmt_scan.c
--- sbr/fmt_scan.c 5 Apr 2008 18:41:37 -0000 1.25
+++ sbr/fmt_scan.c 2 Feb 2010 19:36:05 -0000
@@ -297,7 +297,7 @@
{
char *cp, *ep;
unsigned char *sp;
- char *savestr;
+ char *savestr = NULL;
unsigned char *str = NULL;
char buffer[BUFSIZ], buffer2[BUFSIZ];
int i, c, ljust, n;
Index: sbr/getarguments.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/getarguments.c,v
retrieving revision 1.3
diff -u -r1.3 getarguments.c
--- sbr/getarguments.c 2 Jan 2006 03:17:42 -0000 1.3
+++ sbr/getarguments.c 2 Feb 2010 19:36:05 -0000
@@ -15,7 +15,7 @@
char **
getarguments (char *invo_name, int argc, char **argv, int check_context)
{
- char *cp, **ap, **bp, **arguments;
+ char *cp = NULL, **ap = NULL, **bp = NULL, **arguments = NULL;
int n = 0;
/*
@@ -35,7 +35,7 @@
bp = arguments;
/* Copy any arguments from profile/context */
- if (n > 0) {
+ if (ap != NULL && n > 0) {
while (*ap)
*bp++ = *ap++;
}
Index: sbr/pidwait.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/pidwait.c,v
retrieving revision 1.6
diff -u -r1.6 pidwait.c
--- sbr/pidwait.c 11 Apr 2008 14:12:55 -0000 1.6
+++ sbr/pidwait.c 2 Feb 2010 19:36:05 -0000
@@ -22,7 +22,7 @@
pidwait (pid_t id, int sigsok)
{
pid_t pid;
- SIGNAL_HANDLER istat, qstat;
+ SIGNAL_HANDLER istat = NULL, qstat = NULL;
#ifdef HAVE_UNION_WAIT
union wait status;
Index: uip/annosbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/annosbr.c,v
retrieving revision 1.9
diff -u -r1.9 annosbr.c
--- uip/annosbr.c 5 Apr 2008 18:41:38 -0000 1.9
+++ uip/annosbr.c 2 Feb 2010 19:36:06 -0000
@@ -179,20 +179,15 @@
FILE *tmp;
int c; /* current character */
int count; /* header field (annotation) counter */
- char *field; /* buffer for header field */
- int field_size; /* size of field buffer */
- FILE *fp; /* file pointer made from locked file
descriptor */
+ char *field = NULL; /* buffer for header field */
+ int field_size = 0; /* size of field buffer */
+ FILE *fp = NULL; /* file pointer made from locked file
descriptor */
int length; /* length of field name */
int n; /* number of bytes written */
mode = fstat (fd, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot ();
- strncpy (tmpfil, m_scratch (file, "annotate"), sizeof(tmpfil));
-
- if ((tmp = fopen (tmpfil, "w")) == NULL) {
- admonish (tmpfil, "unable to create");
- return 1;
- }
+ strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil));
chmod (tmpfil, mode);
/*
Index: uip/burst.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/burst.c,v
retrieving revision 1.7
diff -u -r1.7 burst.c
--- uip/burst.c 4 Nov 2007 11:54:33 -0000 1.7
+++ uip/burst.c 2 Feb 2010 19:36:06 -0000
@@ -347,12 +347,11 @@
i = inplace ? msgnum + numburst : mp->hghmsg;
for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
strncpy (f1, m_name (i), sizeof(f1));
- strncpy (f2, m_scratch ("", invo_name), sizeof(f2));
+ strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2));
+
if (verbosw && i != msgnum)
printf ("message %d of digest %d becomes message %d\n", j, msgnum,
i);
- if ((out = fopen (f2, "w")) == NULL)
- adios (f2, "unable to write message");
chmod (f2, mode);
fseek (in, smsgs[j].s_start, SEEK_SET);
cpybrst (in, out, msgnam, f2,
Index: uip/distsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/distsbr.c,v
retrieving revision 1.4
diff -u -r1.4 distsbr.c
--- uip/distsbr.c 13 Apr 2007 11:53:08 -0000 1.4
+++ uip/distsbr.c 2 Feb 2010 19:36:06 -0000
@@ -132,6 +132,7 @@
int state, out;
char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
register FILE *ifp, *ofp;
+ char *cp = NULL;
if (hdrfd != NOTOK)
close (hdrfd), hdrfd = NOTOK;
@@ -141,9 +142,12 @@
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");
@@ -171,9 +175,12 @@
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");
Index: uip/forw.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/forw.c,v
retrieving revision 1.11
diff -u -r1.11 forw.c
--- uip/forw.c 4 Nov 2007 11:54:34 -0000 1.11
+++ uip/forw.c 2 Feb 2010 19:36:07 -0000
@@ -650,10 +650,11 @@
int fmtsize;
register char *nfs;
char *line, tmpfil[BUFSIZ];
- register FILE *tmp;
+ FILE *tmp;
register struct comp *cptr;
struct format *fmt;
int dat[5];
+ char *cp = NULL;
/* Get new format string */
nfs = new_fs (form, NULL, NULL);
@@ -675,9 +676,9 @@
dat[3] = fmtsize;
dat[4] = 0;
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((tmp = fopen (tmpfil, "w+")) == NULL)
- adios (tmpfil, "unable to create");
+ cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
+ if (cp == NULL) adios("forw", "unable to create temporary file");
+ strncpy (tmpfil, cp, sizeof(tmpfil));
unlink (tmpfil);
if ((in = dup (fileno (tmp))) == NOTOK)
adios ("dup", "unable to");
Index: uip/inc.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/inc.c,v
retrieving revision 1.28
diff -u -r1.28 inc.c
--- uip/inc.c 25 Dec 2009 14:47:39 -0000 1.28
+++ uip/inc.c 2 Feb 2010 19:36:08 -0000
@@ -236,18 +236,18 @@
{
int chgflag = 1, trnflag = 1;
int noisy = 1, width = 0;
- int rpop, i, hghnum, msgnum;
+ int rpop, i, hghnum = 0, msgnum = 0;
int kpop = 0, sasl = 0;
- char *cp, *maildir, *folder = NULL;
+ char *cp, *maildir = NULL, *folder = NULL;
char *format = NULL, *form = NULL;
char *host = NULL, *user = NULL, *proxy = NULL;
char *audfile = NULL, *from = NULL, *saslmech = NULL;
char buf[BUFSIZ], **argp, *nfs, **arguments;
- struct msgs *mp;
+ struct msgs *mp = NULL;
struct stat st, s1;
FILE *aud = NULL;
- char b[MAXPATHLEN + 1];
- char *maildir_copy; /* copy of mail directory because the
static gets overwritten */
+ char b[MAXPATHLEN + 1];
+ char *maildir_copy = NULL; /* copy of mail directory because the static
gets overwritten */
#ifdef POP
int nmsgs, nbytes, p = 0;
Index: uip/mhbuild.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhbuild.c,v
retrieving revision 1.14
diff -u -r1.14 mhbuild.c
--- uip/mhbuild.c 14 Aug 2008 00:56:39 -0000 1.14
+++ uip/mhbuild.c 2 Feb 2010 19:36:08 -0000
@@ -104,6 +104,7 @@
/* 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,8 @@
char buffer[BUFSIZ], *compfile = NULL;
char **argp, **arguments;
CT ct, cts[2];
- FILE *fp;
+ FILE *fp = NULL;
+ FILE *fp_out = NULL;
done=unlink_done;
@@ -305,11 +307,8 @@
* 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);
@@ -321,11 +320,12 @@
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)
@@ -354,11 +354,13 @@
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
@@ -368,12 +370,13 @@
/* 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);
}
Index: uip/mhbuildsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhbuildsbr.c,v
retrieving revision 1.19
diff -u -r1.19 mhbuildsbr.c
--- uip/mhbuildsbr.c 14 Aug 2008 00:56:39 -0000 1.19
+++ uip/mhbuildsbr.c 2 Feb 2010 19:36:08 -0000
@@ -414,14 +414,15 @@
long pos;
char content[BUFSIZ];
FILE *out;
+ char *cp;
+
+ cp = m_mktemp2(NULL, invo_name, NULL, &out);
+ if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file");
/* use a temp file to collect the plain text lines */
- ce->ce_file = add (m_tmpfil (invo_name), NULL);
+ ce->ce_file = add (cp, NULL);
ce->ce_unlink = 1;
- if ((out = fopen (ce->ce_file, "w")) == NULL)
- adios (ce->ce_file, "unable to open for writing");
-
if (buf[0] == '#' && buf[1] == '<') {
strncpy (content, buf + 2, sizeof(content));
inlineD = 1;
@@ -1007,11 +1008,16 @@
char *vec[4], buffer[BUFSIZ];
FILE *out;
CI ci = &ct->c_ctinfo;
+ char *tfile = NULL;
if (!(cp = ci->ci_magic))
adios (NULL, "internal error(5)");
- ce->ce_file = add (m_tmpfil (invo_name), NULL);
+ tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+ if (tfile == NULL) {
+ adios("mhbuildsbr", "unable to create temporary file");
+ }
+ ce->ce_file = add (tfile, NULL);
ce->ce_unlink = 1;
xstdout = 0;
@@ -1152,14 +1158,14 @@
scan_content (CT ct)
{
int len;
- int check8bit, contains8bit = 0; /* check if contains 8bit data
*/
- int checklinelen, linelen = 0; /* check for long lines
*/
- int checkboundary, boundaryclash = 0; /* check if clashes with multipart
boundary */
- int checklinespace, linespace = 0; /* check if any line ends with space
*/
- int checkebcdic, ebcdicunsafe = 0; /* check if contains ebcdic unsafe
characters */
- unsigned char *cp, buffer[BUFSIZ];
- struct text *t;
- FILE *in;
+ int check8bit = 0, contains8bit = 0; /* check if contains 8bit data
*/
+ int checklinelen = 0, linelen = 0; /* check for long lines
*/
+ int checkboundary = 0, boundaryclash = 0; /* check if clashes with
multipart boundary */
+ int checklinespace = 0, linespace = 0; /* check if any line ends with
space */
+ int checkebcdic = 0, ebcdicunsafe = 0; /* check if contains ebcdic unsafe
characters */
+ unsigned char *cp = NULL, buffer[BUFSIZ];
+ struct text *t = NULL;
+ FILE *in = NULL;
CE ce = ct->c_cefile;
/*
Index: uip/mhlsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhlsbr.c,v
retrieving revision 1.14
diff -u -r1.14 mhlsbr.c
--- uip/mhlsbr.c 30 Dec 2009 01:42:45 -0000 1.14
+++ uip/mhlsbr.c 2 Feb 2010 19:36:08 -0000
@@ -794,8 +794,8 @@
static void
process (char *folder, char *fname, int ofilen, int ofilec)
{
- char *cp;
- FILE *fp;
+ char *cp = NULL;
+ FILE *fp = NULL;
struct mcomp *c1;
switch (setjmp (env)) {
@@ -1687,8 +1687,8 @@
int
mhlsbr (int argc, char **argv, FILE *(*action)())
{
- SIGNAL_HANDLER istat, pstat, qstat;
- char *cp;
+ SIGNAL_HANDLER istat = NULL, pstat = NULL, qstat = NULL;
+ char *cp = NULL;
struct mcomp *c1;
switch (setjmp (mhlenv)) {
Index: uip/mhmail.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhmail.c,v
retrieving revision 1.6
diff -u -r1.6 mhmail.c
--- uip/mhmail.c 5 Apr 2008 19:04:42 -0000 1.6
+++ uip/mhmail.c 2 Feb 2010 19:36:09 -0000
@@ -52,6 +52,7 @@
char *from = NULL, *body = NULL, **argp, **arguments;
char *vec[5], buf[BUFSIZ];
FILE *out;
+ char *tfile = NULL;
#ifdef LOCALE
setlocale(LC_ALL, "");
@@ -125,10 +126,11 @@
if (tolist == NULL)
adios (NULL, "usage: %s addrs ... [switches]", invo_name);
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((out = fopen (tmpfil, "w")) == NULL)
- adios (tmpfil, "unable to write");
- chmod (tmpfil, 0600);
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, &out);
+ if (tfile == NULL) adios("mhmail", "unable to create temporary file");
+ chmod(tfile, 0600);
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
SIGNAL2 (SIGINT, intrser);
Index: uip/mhoutsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhoutsbr.c,v
retrieving revision 1.8
diff -u -r1.8 mhoutsbr.c
--- uip/mhoutsbr.c 8 Mar 2006 12:14:16 -0000 1.8
+++ uip/mhoutsbr.c 2 Feb 2010 19:36:09 -0000
@@ -70,6 +70,7 @@
* prototypes
*/
int output_message (CT, char *);
+int output_message_fp (CT, FILE *, char *);
int writeBase64aux (FILE *, FILE *);
/*
@@ -90,27 +91,33 @@
*/
int
-output_message (CT ct, char *file)
+output_message_fp (CT ct, FILE *fp, char *file)
{
- FILE *fp;
-
- if ((fp = fopen (file, "w")) == NULL) {
- advise (file, "unable to open for writing");
- return NOTOK;
- }
-
if (output_content (ct, fp) == NOTOK)
return NOTOK;
if (fflush (fp)) {
- advise (file, "error writing to");
+ advise ((file?file:"<FILE*>"), "error writing to");
return NOTOK;
}
- fclose (fp);
-
return OK;
}
+int
+output_message (CT ct, char *file)
+{
+ FILE *fp;
+ int status;
+
+ if ((fp = fopen (file, "w")) == NULL) {
+ advise (file, "unable to open for writing");
+ return NOTOK;
+ }
+ status = output_message_fp(ct, fp, file);
+ fclose(fp);
+ return status;
+}
+
/*
* Output a Content structure to a file.
Index: uip/mhparse.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhparse.c,v
retrieving revision 1.21
diff -u -r1.21 mhparse.c
--- uip/mhparse.c 14 Aug 2008 06:19:08 -0000 1.21
+++ uip/mhparse.c 2 Feb 2010 19:36:11 -0000
@@ -204,12 +204,14 @@
* Check if file is actually standard input
*/
if ((is_stdin = !(strcmp (file, "-")))) {
- file = add (m_tmpfil (invo_name), NULL);
- if ((fp = fopen (file, "w+")) == NULL) {
- advise (file, "unable to fopen for writing and reading");
- return NULL;
- }
+ char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) {
+ advise("mhparse", "unable to create temporary file");
+ return NULL;
+ }
+ file = add (tfile, NULL);
chmod (file, 0600);
+
while (fgets (buffer, sizeof(buffer), stdin))
fputs (buffer, fp);
fflush (fp);
@@ -1764,7 +1766,7 @@
}
if (*file == NULL) {
- ce->ce_file = add (m_scratch ("", tmp), NULL);
+ ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
@@ -1972,7 +1974,7 @@
}
if (*file == NULL) {
- ce->ce_file = add (m_scratch ("", tmp), NULL);
+ ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
@@ -2177,7 +2179,7 @@
}
if (*file == NULL) {
- ce->ce_file = add (m_scratch ("", tmp), NULL);
+ ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
@@ -2545,7 +2547,7 @@
else if (caching)
ce->ce_file = add (cachefile, NULL);
else
- ce->ce_file = add (m_scratch ("", tmp), NULL);
+ ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2747,7 +2749,7 @@
}
if (*file == NULL) {
- ce->ce_file = add (m_scratch ("", tmp), NULL);
+ ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
ce->ce_unlink = 1;
} else {
ce->ce_file = add (*file, NULL);
Index: uip/mhstoresbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhstoresbr.c,v
retrieving revision 1.15
diff -u -r1.15 mhstoresbr.c
--- uip/mhstoresbr.c 4 Jun 2006 08:37:24 -0000 1.15
+++ uip/mhstoresbr.c 2 Feb 2010 19:36:11 -0000
@@ -482,7 +482,7 @@
static int
store_content (CT ct, CT p)
{
- int appending = 0, msgnum;
+ int appending = 0, msgnum = 0;
int is_partial = 0, first_partial = 0;
int last_partial = 0;
char *cp, buffer[BUFSIZ];
@@ -560,7 +560,7 @@
char *tmpfilenam, *folder;
/* Store content in temporary file for now */
- tmpfilenam = m_scratch ("", invo_name);
+ tmpfilenam = m_mktemp(invo_name, NULL, NULL);
ct->c_storage = add (tmpfilenam, NULL);
/* Get the folder name */
Index: uip/msh.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/msh.c,v
retrieving revision 1.14
diff -u -r1.14 msh.c
--- uip/msh.c 14 Aug 2008 01:50:46 -0000 1.14
+++ uip/msh.c 2 Feb 2010 19:36:11 -0000
@@ -733,10 +733,10 @@
#ifdef BPOP
if (pmsh) {
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fp = fopen (tmpfil, "w+")) == NULL)
- padios (tmpfil, "unable to create");
- unlink (tmpfil);
+ char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) padios("msh", "unable to create temporary file");
+ unlink(tfile);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
}
else
#endif /* BPOP */
@@ -996,10 +996,10 @@
if (Msgs[msgnum].m_top == 0)
padios (NULL, "msh_ready (%d, %d) botch", msgnum, full);
if (!full) {
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((yp = fopen (tmpfil, "w+")) == NULL)
- padios (tmpfil, "unable to create");
- unlink (tmpfil);
+ char *tfile = m_mktemp2(NULL, invo_name, NULL, &yp);
+ if (tfile == NULL) padios("msh", "unable to create temporary
file");
+ unlink(tfile);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
if (pop_top (Msgs[msgnum].m_top, 4, pop_action) == NOTOK)
padios (NULL, "%s", response);
@@ -1163,7 +1163,7 @@
void
readids (int id)
{
- register int cur, seqnum, i, msgnum;
+ register int cur, seqnum, i=0, msgnum;
if (mp->curmsg == 0)
seq_setcur (mp, mp->lowmsg);
Index: uip/mshcmds.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mshcmds.c,v
retrieving revision 1.16
diff -u -r1.16 mshcmds.c
--- uip/mshcmds.c 13 Apr 2007 11:53:08 -0000 1.16
+++ uip/mshcmds.c 2 Feb 2010 19:36:12 -0000
@@ -867,6 +867,8 @@
int msgp = 0, vecp = 1, msgnum;
char *cp, *filter = NULL, buf[BUFSIZ];
char *msgs[MAXARGS], *vec[MAXARGS];
+ char *tfile = NULL;
+ char tmpfil[BUFSIZ];
if (fmsh) {
forkcmd (args, cmd_name);
@@ -939,16 +941,12 @@
/* foil search of .mh_profile */
snprintf (buf, sizeof(buf), "%sXXXXXX", invo_name);
-/*
- Mkstemp work postponed until later -Doug
-#ifdef HAVE_MKSTEMP
- vec[0] = (char *)mkstemp (buf);
-#else
-*/
- vec[0] = (char *)mktemp (buf);
-/*
-#endif
-*/
+
+ tfile = m_mktemp(buf, NULL, NULL);
+ if (tfile == NULL) adios("forwcmd", "unable to create temporary file");
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
+ vec[0] = tmpfil;
+
vec[vecp++] = "-file";
vec[vecp] = NULL;
if (!msgp)
@@ -979,10 +977,14 @@
forw (char *proc, char *filter, int vecp, char **vec)
{
int i, child_id, msgnum, msgcnt;
- char tmpfil[80], *args[MAXARGS];
+ char tmpfil[BUFSIZ], *args[MAXARGS];
FILE *out;
+ char *tfile = NULL;
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+ if (tfile == NULL) adios("forw", "unable to create temporary file");
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
interrupted = 0;
if (filter)
switch (child_id = fork ()) {
@@ -2995,8 +2997,9 @@
process (int msgnum, char *proc, int vecp, char **vec)
{
int child_id, status;
- char tmpfil[80];
+ char tmpfil[BUFSIZ];
FILE *out;
+ char *cp;
if (fmsh) {
strncpy (tmpfil, m_name (msgnum), sizeof(tmpfil));
@@ -3007,23 +3010,20 @@
goto ready;
}
- strncpy (tmpfil, m_scratch ("", invo_name), sizeof(tmpfil));
- if ((out = fopen (tmpfil, "w")) == NULL) {
- int olderr;
- char newfil[80];
-
- olderr = errno;
- strncpy (newfil, m_tmpfil (invo_name), sizeof(newfil));
- if ((out = fopen (newfil, "w")) == NULL) {
+ cp = m_mktemp(invo_name, NULL, &out);
+ if (cp == NULL) {
+ /* Try again, but try to create under /tmp */
+ int olderr = errno;
+ cp = m_mktemp2(NULL, invo_name, NULL, &out);
+ if (cp == NULL) {
errno = olderr;
- advise (tmpfil, "unable to create temporary file");
+ advise (NULL, "unable to create temporary file");
return NOTOK;
- } else {
- strncpy (tmpfil, newfil, sizeof(tmpfil));
}
}
copy_message (msgnum, out);
fclose (out);
+ strncpy(tmpfil, cp, sizeof(tmpfil));
ready: ;
fflush (stdout);
@@ -3089,7 +3089,7 @@
copy_digest (int msgnum, FILE *out)
{
char c;
- long pos;
+ long pos = 0L;
static char buffer[BUFSIZ];
register FILE *zp;
Index: uip/new.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/new.c,v
retrieving revision 1.2
diff -u -r1.2 new.c
--- uip/new.c 30 Dec 2009 01:41:47 -0000 1.2
+++ uip/new.c 2 Feb 2010 19:36:12 -0000
@@ -300,7 +300,7 @@
struct node *first, *cur_node, *node, *last, *prev;
size_t folder_len;
int count, total = 0;
- char *command, *sequences_s;
+ char *command = NULL, *sequences_s = NULL;
if (cur == NULL || cur[0] == '\0') {
cur = "inbox";
Index: uip/popsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/popsbr.c,v
retrieving revision 1.20
diff -u -r1.20 popsbr.c
--- uip/popsbr.c 16 Jan 2009 02:28:55 -0000 1.20
+++ uip/popsbr.c 2 Feb 2010 19:36:12 -0000
@@ -1103,7 +1103,7 @@
static int
sasl_getline (char *s, int n, FILE *iop)
{
- int c;
+ int c = -2;
char *p;
p = s;
Index: uip/post.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/post.c,v
retrieving revision 1.23
diff -u -r1.23 post.c
--- uip/post.c 16 Jan 2009 02:28:55 -0000 1.23
+++ uip/post.c 2 Feb 2010 19:36:14 -0000
@@ -554,13 +554,14 @@
if ((out = fopen (fill_in ? fill_in : "/dev/null", "w")) == NULL)
adios ("/dev/null", "unable to open");
} else {
- strncpy (tmpfil, m_scratch ("", m_maildir (invo_name)),
- sizeof(tmpfil));
- if ((out = fopen (tmpfil, "w")) == NULL) {
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((out = fopen (tmpfil, "w")) == NULL)
- adios (tmpfil, "unable to create");
- }
+ char *cp = m_mktemp(m_maildir(invo_name), NULL, &out);
+ if (cp == NULL) {
+ cp = m_mktemp2(NULL, invo_name, NULL, &out);
+ if (cp == NULL) {
+ adios ("post", "unable to create temporary file");
+ }
+ }
+ strncpy(tmpfil, cp, sizeof(tmpfil));
chmod (tmpfil, 0600);
}
}
@@ -662,7 +663,7 @@
int count, grp, i, keep;
char *cp, *pp, *qp;
char namep[BUFSIZ];
- struct mailname *mp, *np;
+ struct mailname *mp = NULL, *np = NULL;
struct headers *hdr;
while (*str == ' ' || *str == '\t')
@@ -1166,11 +1167,12 @@
pid_t child_id;
char *vec[6];
FILE *out;
+ char *tfile = NULL;
- strncpy (bccfil, m_tmpfil ("bccs"), sizeof(bccfil));
- if ((out = fopen (bccfil, "w")) == NULL)
- adios (bccfil, "unable to create");
+ tfile = m_mktemp2(NULL, "bccs", NULL, &out);
+ if (tfile == NULL) adios("bcc", "unable to create temporary file");
chmod (bccfil, 0600);
+ strncpy (bccfil, tfile, sizeof(bccfil));
fprintf (out, "Date: %s\n", dtime (&tclock, 0));
if (msgid)
Index: uip/prompter.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/prompter.c,v
retrieving revision 1.6
diff -u -r1.6 prompter.c
--- uip/prompter.c 4 Nov 2007 11:54:35 -0000 1.6
+++ uip/prompter.c 2 Feb 2010 19:36:14 -0000
@@ -108,6 +108,7 @@
char buffer[BUFSIZ], tmpfil[BUFSIZ];
char **arguments, **argp;
FILE *in, *out;
+ char *tfile = NULL;
#ifdef LOCALE
setlocale(LC_ALL, "");
@@ -185,10 +186,10 @@
if ((in = fopen (drft, "r")) == NULL)
adios (drft, "unable to open");
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((out = fopen (tmpfil, "w")) == NULL)
- adios (tmpfil, "unable to create");
+ tfile = m_mktemp2(NULL, invo_name, NULL, &out);
+ if (tfile == NULL) adios("prompter", "unable to create temporary file");
chmod (tmpfil, 0600);
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
/*
* Are we changing the kill or erase character?
Index: uip/rcvdist.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/rcvdist.c,v
retrieving revision 1.13
diff -u -r1.13 rcvdist.c
--- uip/rcvdist.c 2 Jun 2008 22:37:02 -0000 1.13
+++ uip/rcvdist.c 2 Feb 2010 19:36:14 -0000
@@ -44,7 +44,8 @@
int i, vecp = 1;
char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ];
char **argp, **arguments, *vec[MAXARGS];
- register FILE *fp;
+ FILE *fp;
+ char *tfile = NULL;
done=unlink_done;
@@ -94,12 +95,18 @@
invo_name);
umask (~m_gmprot ());
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fp = fopen (tmpfil, "w+")) == NULL)
- adios (tmpfil, "unable to create");
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
+
cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
fseek (fp, 0L, SEEK_SET);
- strncpy (drft, m_tmpfil (invo_name), sizeof(drft));
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+ if (tfile == NULL) adios("forw", "unable to create temporary file");
+ strncpy (drft, tfile, sizeof(tmpfil));
+
rcvdistout (fp, form, addrs);
fclose (fp);
Index: uip/rcvstore.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/rcvstore.c,v
retrieving revision 1.14
diff -u -r1.14 rcvstore.c
--- uip/rcvstore.c 2 Jun 2008 22:37:02 -0000 1.14
+++ uip/rcvstore.c 2 Feb 2010 19:36:14 -0000
@@ -173,9 +173,10 @@
SIGNAL (SIGTERM, SIG_IGN);
/* create a temporary file */
- tmpfilenam = m_scratch ("", invo_name);
- if ((fd = creat (tmpfilenam, m_gmprot ())) == NOTOK)
- adios (tmpfilenam, "unable to create");
+ tmpfilenam = m_mktemp (invo_name, &fd, NULL);
+ if (tmpfilenam == NULL) {
+ adios ("rcvstore", "unable to create temporary file");
+ }
chmod (tmpfilenam, m_gmprot());
/* copy the message from stdin into temp file */
Index: uip/rcvtty.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/rcvtty.c,v
retrieving revision 1.14
diff -u -r1.14 rcvtty.c
--- uip/rcvtty.c 11 Apr 2008 14:12:55 -0000 1.14
+++ uip/rcvtty.c 2 Feb 2010 19:36:14 -0000
@@ -287,12 +287,12 @@
header_fd (void)
{
int fd;
- char *nfs, tmpfil[BUFSIZ];
+ char *nfs;
+ char *tfile = NULL;
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
- return NOTOK;
- unlink (tmpfil);
+ tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+ if (tfile == NULL) return NOTOK;
+ unlink (tfile);
rewind (stdin);
Index: uip/scansbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/scansbr.c,v
retrieving revision 1.13
diff -u -r1.13 scansbr.c
--- uip/scansbr.c 8 Aug 2008 23:45:24 -0000 1.13
+++ uip/scansbr.c 2 Feb 2010 19:36:14 -0000
@@ -81,11 +81,11 @@
int i, compnum, encrypted, state;
unsigned char *cp, *tmpbuf;
char **nxtbuf;
- char *saved_c_text;
+ char *saved_c_text = NULL;
struct comp *cptr;
struct comp **savecomp;
- char *scnmsg;
- FILE *scnout;
+ char *scnmsg = NULL;
+ FILE *scnout = NULL;
char name[NAMESZ];
static int rlwidth, slwidth;
Index: uip/send.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/send.c,v
retrieving revision 1.10
diff -u -r1.10 send.c
--- uip/send.c 16 Jan 2009 02:28:55 -0000 1.10
+++ uip/send.c 2 Feb 2010 19:36:14 -0000
@@ -423,7 +423,7 @@
&& (distsw = atoi (cp))
&& altmsg) {
vec[vecp++] = "-dist";
- distfile = getcpy (m_scratch (altmsg, invo_name));
+ distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
if (link (altmsg, distfile) == NOTOK) {
if (errno != EXDEV
#ifdef EISREMOTE
@@ -432,7 +432,7 @@
)
adios (distfile, "unable to link %s to", altmsg);
free (distfile);
- distfile = getcpy (m_tmpfil (invo_name));
+ distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
{
int in, out;
struct stat st;
Index: uip/sendsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/sendsbr.c,v
retrieving revision 1.18
diff -u -r1.18 sendsbr.c
--- uip/sendsbr.c 2 Jun 2008 22:37:02 -0000 1.18
+++ uip/sendsbr.c 2 Feb 2010 19:36:15 -0000
@@ -125,8 +125,11 @@
* rename the draft file. I'm not quite sure why.
*/
if (pushsw && unique) {
- if (rename (drft, strncpy (file, m_scratch (drft, invo_name),
sizeof(file)))
- == NOTOK)
+ char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+ if (cp == NULL) {
+ adios ("sendsbr", "unable to create temporary file");
+ }
+ if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
adios (file, "unable to rename %s to", drft);
drft = file;
}
@@ -253,8 +256,12 @@
* Make names for the temporary files.
*/
- (void)strncpy(body_file_name, m_scratch("", m_maildir(invo_name)), sizeof
(body_file_name));
- (void)strncpy(composition_file_name, m_scratch("", m_maildir(invo_name)),
sizeof (composition_file_name));
+ (void)strncpy(body_file_name,
+ m_mktemp(m_maildir(invo_name), NULL, NULL),
+ sizeof (body_file_name));
+ (void)strncpy(composition_file_name,
+ m_mktemp(m_maildir(invo_name), NULL, NULL),
+ sizeof (composition_file_name));
if (has_body)
body_file = fopen(body_file_name, "w");
@@ -676,9 +683,11 @@
char tmpdrf[BUFSIZ];
FILE *out;
- strncpy (tmpdrf, m_scratch (drft, invo_name), sizeof(tmpdrf));
- if ((out = fopen (tmpdrf, "w")) == NULL)
- adios (tmpdrf, "unable to open for writing");
+ char *cp = m_mktemp2(drft, invo_name, NULL, &out);
+ if (cp == NULL) {
+ adios (drft, "unable to create temporary file for");
+ }
+ strncpy(tmpdrf, cp, sizeof(tmpdrf));
chmod (tmpdrf, 0600);
/*
@@ -919,16 +928,17 @@
tmp_fd (void)
{
int fd;
- char tmpfil[BUFSIZ];
+ char *tfile = NULL;
+
+ tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+ if (tfile == NULL) return NOTOK;
+ fchmod(fd, 0600);
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
- return NOTOK;
if (debugsw)
- advise (NULL, "temporary file %s selected", tmpfil);
+ advise (NULL, "temporary file %s selected", tfile);
else
- if (unlink (tmpfil) == NOTOK)
- advise (tmpfil, "unable to remove");
+ if (unlink (tfile) == NOTOK)
+ advise (tfile, "unable to remove");
return fd;
}
Index: uip/show.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/show.c,v
retrieving revision 1.10
diff -u -r1.10 show.c
--- uip/show.c 13 Apr 2007 11:53:08 -0000 1.10
+++ uip/show.c 2 Feb 2010 19:36:15 -0000
@@ -71,7 +71,7 @@
char *cp, *maildir, *file = NULL, *folder = NULL, *proc;
char buf[BUFSIZ], **argp, **arguments;
char *msgs[MAXARGS], *vec[MAXARGS];
- struct msgs *mp;
+ struct msgs *mp = NULL;
#ifdef LOCALE
setlocale(LC_ALL, "");
Index: uip/slocal.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/slocal.c,v
retrieving revision 1.27
diff -u -r1.27 slocal.c
--- uip/slocal.c 11 Apr 2008 14:12:55 -0000 1.27
+++ uip/slocal.c 2 Feb 2010 19:36:16 -0000
@@ -1274,12 +1274,12 @@
int i, first = 1, fd1, fd2;
char buffer[BUFSIZ];
FILE *qfp, *ffp;
+ char *tfile = NULL;
- strcpy (tmpfil, m_tmpfil (invo_name));
-
- /* open temporary file to put message in */
- if ((fd1 = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == -1)
- return -1;
+ tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
+ if (tfile == NULL) return -1;
+ fchmod(fd1, 0600);
+ strncpy (tmpfil, tfile, BUFSIZ);
if (!fold) {
while ((i = read (qd, buffer, sizeof(buffer))) > 0)
Index: uip/viamail.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/viamail.c,v
retrieving revision 1.11
diff -u -r1.11 viamail.c
--- uip/viamail.c 4 Nov 2007 11:54:36 -0000 1.11
+++ uip/viamail.c 2 Feb 2010 19:36:16 -0000
@@ -181,13 +181,14 @@
char *vec[MAXARGS];
struct stat st;
FILE *fp;
+ char *tfile = NULL;
umask (~m_gmprot ());
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fp = fopen (tmpfil, "w+")) == NULL)
- adios (tmpfil, "unable to open for writing");
- chmod (tmpfil, 0600);
+ tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) adios("viamail", "unable to create temporary file");
+ chmod(tfile, 0600);
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
if (!strchr(mailsw, '@'))
mailsw = concat (mailsw, "@", LocalName (), NULL);
Index: uip/whatnowsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/whatnowsbr.c,v
retrieving revision 1.13
diff -u -r1.13 whatnowsbr.c
--- uip/whatnowsbr.c 21 Jan 2009 19:38:36 -0000 1.13
+++ uip/whatnowsbr.c 2 Feb 2010 19:36:16 -0000
@@ -634,7 +634,7 @@
struct stat st;
#ifdef HAVE_LSTAT
- int slinked;
+ int slinked = 0;
#if 0
int oumask; /* PJS: for setting permissions on symlinks. */
#endif
@@ -1315,7 +1315,7 @@
#endif /* not lint */
&& altmsg) {
vec[vecp++] = "-dist";
- distfile = getcpy (m_scratch (altmsg, invo_name));
+ distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
if (link (altmsg, distfile) == NOTOK)
adios (distfile, "unable to link %s to", altmsg);
} else {
/*
* m_mktemp.c -- Construct a temporary file.
*
* $Id: m_mktemp.c,v 1.4 2002/07/02 22:09:14 kenh Exp $
*
* This code is Copyright (c) 2010, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
#include <errno.h>
#include <h/mh.h>
char *
m_mktemp (
const char *pfx_in, /* Pathname prefix for temporary file. */
int *fd_ret, /* (return,optional) File descriptor to temp file. */
FILE **fp_ret /* (return,optional) FILE pointer to temp file. */
)
{
static char tmpfil[BUFSIZ];
const char *pfx = (pfx_in == NULL) ? "/tmp/nmh" : pfx_in;
int fd = -1;
int keep_open = 0;
snprintf(tmpfil, sizeof(tmpfil), "%sXXXXXX", pfx);
fd = mkstemp(tmpfil);
if (fd < 0) {
return NULL;
}
if (fd_ret != NULL) {
*fd_ret = fd;
keep_open = 1;
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
if (fp == NULL) {
int olderr = errno;
unlink(tmpfil);
close(fd);
errno = olderr;
return NULL;
}
*fp_ret = fp;
keep_open = 1;
}
if (!keep_open) {
close(fd);
}
return tmpfil;
}
/* This version allows one to specify the directory the temp file should
* by created based on a given pathname. The pfx_in parameter specifies
* a basename prefix for the file. If dir_in is NULL, then the system
* temporary directory will be used for containing the temporary file.
*/
char *
m_mktemp2 (
const char *dir_in, /* Directory to place temp file. */
const char *pfx_in, /* Basename prefix for temp file. */
int *fd_ret, /* (return,optional) File descriptor to temp file. */
FILE **fp_ret /* (return,optional) FILE pointer to temp file. */
)
{
static char buffer[BUFSIZ];
char *cp;
if (dir_in == NULL) {
if (pfx_in == NULL) {
return m_mktemp(NULL, fd_ret, fp_ret);
}
snprintf(buffer, sizeof(buffer), "/tmp/%s", pfx_in);
return m_mktemp(buffer, fd_ret, fp_ret);
}
if ((cp = r1bindex ((char *)dir_in, '/')) == dir_in) {
/* No directory component */
return m_mktemp(pfx_in, fd_ret, fp_ret);
}
int n = (int)(cp-dir_in-1); /* Length of dir component */
snprintf(buffer, sizeof(buffer), "%.*s%s", n, dir_in, pfx_in);
return m_mktemp(buffer, fd_ret, fp_ret);
}
_______________________________________________
Nmh-workers mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/nmh-workers