From 5f50d60eff3ef0d7a361ce7de3b6a576ce209c40 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 3 Dec 2017 13:23:43 +0200 Subject: [PATCH] Restored handling of tmpfileplus() keep argument for POSIX targets --- src/tmpfileplus.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tmpfileplus.cpp b/src/tmpfileplus.cpp index 2085e8be3b..2c14e1563d 100644 --- a/src/tmpfileplus.cpp +++ b/src/tmpfileplus.cpp @@ -139,8 +139,8 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, FString *t int oflag, pmode; /* In Windows, we use the _O_TEMPORARY flag with `open` to ensure the file is deleted when closed. - * In Unix, we use the unlink function after opening the file. (This does not work in Windows, - * which does not allow an open file to be unlinked.) + * In Unix, we use the remove function after opening the file. (This does not work in Windows, + * which does not allow an open file to be deleted.) */ #ifdef _WIN32 /* MSVC flags */ @@ -172,6 +172,12 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, FString *t { /* Success, so return user a proper ANSI C file pointer */ fp = FDOPEN_(fd, "w+b"); errno = 0; + +#ifndef _WIN32 + /* [Unix only] And make sure the file will be deleted once closed */ + if (!keep) remove(tempname); +#endif + } else { /* We failed */