Use save mktemp on windows

kimkulling/add_windows_clang_issue-5519
Kim Kulling 2024-04-18 11:44:33 +02:00 committed by GitHub
parent 200e34f0ca
commit a53bca85cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 9 deletions

View File

@ -55,12 +55,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# define _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS
# endif # endif
#include <io.h> #include <io.h>
inline FILE* MakeTmpFile(char* tmplate) inline FILE* MakeTmpFile(char* tmplate) {
{ auto pathtemplate = template;
auto pathtemplate = _mktemp(tmplate); int err = _mktemp_s(pathtemplate, std::strlen(pathtemplate));
EXPECT_EQ(err, 0);
EXPECT_NE(pathtemplate, nullptr); EXPECT_NE(pathtemplate, nullptr);
if(pathtemplate == nullptr) if(pathtemplate == nullptr) {
{
return nullptr; return nullptr;
} }
auto* fs = std::fopen(pathtemplate, "w+"); auto* fs = std::fopen(pathtemplate, "w+");
@ -69,12 +69,10 @@ inline FILE* MakeTmpFile(char* tmplate)
return fs; return fs;
} }
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
inline FILE* MakeTmpFile(char* tmplate) inline FILE* MakeTmpFile(char* tmplate) {
{
auto fd = mkstemp(tmplate); auto fd = mkstemp(tmplate);
EXPECT_NE(-1, fd); EXPECT_NE(-1, fd);
if(fd == -1) if(fd == -1) {
{
return nullptr; return nullptr;
} }
auto fs = fdopen(fd, "w+"); auto fs = fdopen(fd, "w+");