diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2015-04-01 20:17:57 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2015-04-01 20:17:57 +0000 |
commit | 8afcac6f05b2a518d55369c45736dff18a399f64 (patch) | |
tree | 2205883f055353ce117f399904f821a156964ede | |
parent | 41442fb443c474f466f786b51b5685f8a1517286 (diff) |
Use mkstemp to generate a new temporary file name.
ok millert
-rw-r--r-- | usr.bin/sort/file.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index 6c4c0a2524d..e8f1d924d9b 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.6 2015/04/01 19:06:18 millert Exp $ */ +/* $OpenBSD: file.c,v 1.7 2015/04/01 20:17:56 tobias Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -167,12 +167,13 @@ file_is_tmp(const char *fn) char * new_tmp_file_name(void) { - static size_t tfcounter = 0; - static const char *fn = ".bsdsort."; char *ret; + int fd; - sort_asprintf(&ret, "%s/%s%d.%lu", tmpdir, fn, (int)getpid(), - (unsigned long)(tfcounter++)); + sort_asprintf(&ret, "%s/.bsdsort.XXXXXXXXXX", tmpdir); + if ((fd = mkstemp(ret)) == -1) + err(2, "%s", ret); + close(fd); tmp_file_atexit(ret); return ret; } |