diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-24 16:23:40 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-24 16:23:40 +0000 |
commit | 87126afafdf5a85a141fd683006666504dffcb19 (patch) | |
tree | 4f4057478fd7e6dfd330e0c09841f285358f0c55 /usr.bin | |
parent | 517850cb56fa3581feb8f15841fe9c203c9dbf1d (diff) |
Replace 3 tempnam()'s with mkstemp. The two left look tricky.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mail/extern.h | 5 | ||||
-rw-r--r-- | usr.bin/mail/fio.c | 5 | ||||
-rw-r--r-- | usr.bin/mail/lex.c | 21 | ||||
-rw-r--r-- | usr.bin/mail/quit.c | 41 | ||||
-rw-r--r-- | usr.bin/mail/temp.c | 10 |
5 files changed, 41 insertions, 41 deletions
diff --git a/usr.bin/mail/extern.h b/usr.bin/mail/extern.h index 73ece3ffa21..a46540d8369 100644 --- a/usr.bin/mail/extern.h +++ b/usr.bin/mail/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.7 1997/07/22 18:54:38 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.8 1997/07/24 16:23:36 millert Exp $ */ /* $NetBSD: extern.h,v 1.7 1997/07/09 05:22:00 mikel Exp $ */ /*- @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)extern.h 8.2 (Berkeley) 4/20/95 - * $OpenBSD: extern.h,v 1.7 1997/07/22 18:54:38 millert Exp $ + * $OpenBSD: extern.h,v 1.8 1997/07/24 16:23:36 millert Exp $ */ struct name; @@ -269,3 +269,4 @@ int wait_command __P((int)); int writeback __P((FILE *)); extern char *__progname; +extern char *tmpdir; diff --git a/usr.bin/mail/fio.c b/usr.bin/mail/fio.c index 11c325c2afc..90bebf42427 100644 --- a/usr.bin/mail/fio.c +++ b/usr.bin/mail/fio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fio.c,v 1.8 1997/07/14 00:24:26 millert Exp $ */ +/* $OpenBSD: fio.c,v 1.9 1997/07/24 16:23:37 millert Exp $ */ /* $NetBSD: fio.c,v 1.8 1997/07/07 22:57:55 phil Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: fio.c,v 1.8 1997/07/14 00:24:26 millert Exp $"; +static char rcsid[] = "$OpenBSD: fio.c,v 1.9 1997/07/24 16:23:37 millert Exp $"; #endif #endif /* not lint */ @@ -65,7 +65,6 @@ setptr(ibuf, offset) register FILE *ibuf; off_t offset; { - extern char *tmpdir; register int c, count; register char *cp, *cp2; struct message this; diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index a4bf2c66b48..85f1d9bf74f 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.10 1997/07/22 19:13:25 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.11 1997/07/24 16:23:38 millert Exp $ */ /* $NetBSD: lex.c,v 1.10 1997/05/17 19:55:13 pk Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)lex.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: lex.c,v 1.10 1997/07/22 19:13:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: lex.c,v 1.11 1997/07/24 16:23:38 millert Exp $"; #endif #endif /* not lint */ @@ -66,12 +66,12 @@ setfile(name) char *name; { FILE *ibuf; - int i; + int i, fd; struct stat stb; char isedit = *name != '%'; char *who = name[1] ? name + 1 : myname; + char tempname[MAXPATHLEN]; static int shudclob; - extern char *tempMesg; if ((name = expand(name)) == NULL) return(-1); @@ -137,13 +137,16 @@ setfile(name) if (name != mailname) strcpy(mailname, name); mailsize = fsize(ibuf); - if ((otf = fopen(tempMesg, "w")) == NULL) - err(1, tempMesg); + (void)snprintf(tempname, sizeof(tempname), + "%s/mail.RxXXXXXXXXXX", tmpdir); + if ((fd = mkstemp(tempname)) == -1 || + (otf = fdopen(fd, "w")) == NULL) + err(1, tempname); (void)fcntl(fileno(otf), F_SETFD, 1); - if ((itf = fopen(tempMesg, "r")) == NULL) - err(1, tempMesg); + if ((itf = fopen(tempname, "r")) == NULL) + err(1, tempname); (void)fcntl(fileno(itf), F_SETFD, 1); - rm(tempMesg); + rm(tempname); setptr(ibuf, 0); setmsize(msgCount); /* diff --git a/usr.bin/mail/quit.c b/usr.bin/mail/quit.c index 57c4a8ceca2..819f2ced2c8 100644 --- a/usr.bin/mail/quit.c +++ b/usr.bin/mail/quit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quit.c,v 1.6 1997/07/14 00:24:29 millert Exp $ */ +/* $OpenBSD: quit.c,v 1.7 1997/07/24 16:23:39 millert Exp $ */ /* $NetBSD: quit.c,v 1.6 1996/12/28 07:11:07 tls Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: quit.c,v 1.6 1997/07/14 00:24:29 millert Exp $"; +static char rcsid[] = "$OpenBSD: quit.c,v 1.7 1997/07/24 16:23:39 millert Exp $"; #endif #endif /* not lint */ @@ -79,10 +79,9 @@ quit() int mcount, p, modify, autohold, anystat, holdbit, nohold; FILE *ibuf = NULL, *obuf, *fbuf, *rbuf, *readstat = NULL, *abuf; register struct message *mp; - register int c; - extern char *tempQuit, *tempResid; + int c, fd; struct stat minfo; - char *mbox; + char *mbox, tempname[MAXPATHLEN]; /* * If we are read only, we can't do anything, @@ -124,8 +123,10 @@ quit() rbuf = NULL; if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { puts("New mail has arrived."); - rbuf = Fopen(tempResid, "w"); - if (rbuf == NULL || fbuf == NULL) + (void)snprintf(tempname, sizeof(tempname), + "%s/mail.RqXXXXXXXXXX", tmpdir); + if ((fd = mkstemp(tempname)) == -1 || + (rbuf = Fdopen(fd, "w")) == NULL) goto newmail; #ifdef APPEND fseek(fbuf, (long)mailsize, 0); @@ -141,9 +142,9 @@ quit() } #endif (void)Fclose(rbuf); - if ((rbuf = Fopen(tempResid, "r")) == NULL) + if ((rbuf = Fopen(tempname, "r")) == NULL) goto newmail; - rm(tempResid); + rm(tempname); } /* @@ -216,28 +217,31 @@ quit() mbox = expand("&"); mcount = c; if (value("append") == NULL) { - if ((obuf = Fopen(tempQuit, "w")) == NULL) { - warn(tempQuit); + (void)snprintf(tempname, sizeof(tempname), + "%s/mail.RmXXXXXXXXXX", tmpdir); + if ((fd = mkstemp(tempname)) == -1 || + (obuf = Fdopen(fd, "w")) == NULL) { + warn(tempname); (void)Fclose(fbuf); spool_unlock(); return; } - if ((ibuf = Fopen(tempQuit, "r")) == NULL) { - warn(tempQuit); - rm(tempQuit); + if ((ibuf = Fopen(tempname, "r")) == NULL) { + warn(tempname); + rm(tempname); (void)Fclose(obuf); (void)Fclose(fbuf); spool_unlock(); return; } - rm(tempQuit); + rm(tempname); if ((abuf = Fopen(mbox, "r")) != NULL) { while ((c = getc(abuf)) != EOF) (void)putc(c, obuf); (void)Fclose(abuf); } if (ferror(obuf)) { - warn(tempQuit); + warn(tempname); (void)Fclose(ibuf); (void)Fclose(obuf); (void)Fclose(fbuf); @@ -414,7 +418,6 @@ writeback(res) void edstop() { - extern char *tmpdir; register int gotcha, c; register struct message *mp; FILE *obuf, *ibuf, *readstat = NULL; @@ -450,8 +453,8 @@ edstop() if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) { int fd; - snprintf(tempname, sizeof(tempname), "%s/%s", tmpdir, - "mboxXXXXXXXXXX"); + snprintf(tempname, sizeof(tempname), "%s/mbox.XXXXXXXXXX", + tmpdir); if ((fd = mkstemp(tempname)) == -1 || (obuf = Fdopen(fd, "w")) == NULL) { warn(tempname); diff --git a/usr.bin/mail/temp.c b/usr.bin/mail/temp.c index a209a1f5e6a..97509ad274b 100644 --- a/usr.bin/mail/temp.c +++ b/usr.bin/mail/temp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: temp.c,v 1.7 1997/07/14 00:24:31 millert Exp $ */ +/* $OpenBSD: temp.c,v 1.8 1997/07/24 16:23:39 millert Exp $ */ /* $NetBSD: temp.c,v 1.5 1996/06/08 19:48:42 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: temp.c,v 1.7 1997/07/14 00:24:31 millert Exp $"; +static char rcsid[] = "$OpenBSD: temp.c,v 1.8 1997/07/24 16:23:39 millert Exp $"; #endif #endif /* not lint */ @@ -52,10 +52,7 @@ static char rcsid[] = "$OpenBSD: temp.c,v 1.7 1997/07/14 00:24:31 millert Exp $" */ char *tempMail; -char *tempQuit; char *tempEdit; -char *tempResid; -char *tempMesg; char *tmpdir; void @@ -76,10 +73,7 @@ tinit() } tempMail = tempnam(tmpdir, "Rs"); - tempResid = tempnam(tmpdir, "Rq"); - tempQuit = tempnam(tmpdir, "Rm"); tempEdit = tempnam(tmpdir, "Re"); - tempMesg = tempnam(tmpdir, "Rx"); /* * It's okay to call savestr in here because main will |