diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-06-17 08:31:16 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-06-17 08:31:16 +0000 |
commit | e0b95274df2684f64e033e5dd525cb6a2efad3b2 (patch) | |
tree | 1cbd45747dfbb3c61e1c7f2803274dd158080488 /usr.sbin/ctm/ctm_rmail/ctm_rmail.c | |
parent | 5bb7bd7b0f6db744637715eb1b771a6215a3e317 (diff) |
mkstemp it in the correct place, ok?
Diffstat (limited to 'usr.sbin/ctm/ctm_rmail/ctm_rmail.c')
-rw-r--r-- | usr.sbin/ctm/ctm_rmail/ctm_rmail.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/usr.sbin/ctm/ctm_rmail/ctm_rmail.c b/usr.sbin/ctm/ctm_rmail/ctm_rmail.c index 6b019221bd5..4ab9eb564d0 100644 --- a/usr.sbin/ctm/ctm_rmail/ctm_rmail.c +++ b/usr.sbin/ctm/ctm_rmail/ctm_rmail.c @@ -292,6 +292,7 @@ read_piece(char *input_file) if (!decoding) { char *s; + int fd = -1; if (sscanf(line, "CTM_MAIL BEGIN %s %d %d %c", delta, &pce, &npieces, junk) != 3) @@ -302,16 +303,16 @@ read_piece(char *input_file) got_one++; strcpy(tname, piece_dir); - strcat(tname, "/p.XXXXXX"); - if (mktemp(tname) == NULL) + strcat(tname, "/p.XXXXXXXXXX"); + if ((fd = mkstemp(tname)) == -1 || + (ofp = fdopen(fd, "w")) == NULL) { - err("*mktemp: '%s'", tname); - status++; - continue; - } - if ((ofp = fopen(tname, "w")) == NULL) - { - err("cannot open '%s' for writing", tname); + if (fd != -1) { + err("cannot open '%s' for writing", tname); + close(fd); + } + else + err("*mkstemp: '%s'", tname); status++; continue; } @@ -494,17 +495,19 @@ combine(char *delta, int npieces, char *dname, char *pname, char *tname) FILE *dfp, *pfp; int i, n, e; char buf[BUFSIZ]; + int fd = -1; strcpy(tname, delta_dir); - strcat(tname, "/d.XXXXXX"); - if (mktemp(tname) == NULL) + strcat(tname, "/d.XXXXXXXXXX"); + if ((fd = mkstemp(tname)) == -1 || + (dfp = fdopen(fd, "w")) == NULL) { - err("*mktemp: '%s'", tname); - return 0; - } - if ((dfp = fopen(tname, "w")) == NULL) - { - err("cannot open '%s' for writing", tname); + if (fd != -1) { + close(fd); + err("cannot open '%s' for writing", tname); + } + else + err("*mktemp: '%s'", tname); return 0; } |