From bd8c4079daae0e7d886ba1c828e005076549fb41 Mon Sep 17 00:00:00 2001 From: Alex Sierra Date: Wed, 15 Mar 2023 13:56:35 -0500 Subject: [PATCH] use mkstemp instead tempnam for temp file tempnam has been marked as obsolete. Signed-off-by: Alex Sierra Change-Id: Ie64d9a351bf386da00a96ceff059f685e11f2cca [ROCm/ROCR-Runtime commit: e82025bffa693d8b533018260579958bd63dd124] --- .../hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp index 150840dd46..a1247de7f7 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code_util.cpp @@ -957,12 +957,8 @@ int OpenTempFile(const char* prefix) #ifdef _WIN32 char dir[MAX_PATH+1]; if (!GetTempPath(sizeof(dir), dir)) { return -1; } -#else // _WIN32 - char *dir = NULL; -#endif // _WIN32 char *name = _tempnam(dir, tname.c_str()); if (!name) { return -1; } -#ifdef _WIN32 HANDLE h = CreateFile( name, GENERIC_READ | GENERIC_WRITE, @@ -975,10 +971,10 @@ int OpenTempFile(const char* prefix) if (h == INVALID_HANDLE_VALUE) { continue; } return _open_osfhandle((intptr_t)h, 0); #else // _WIN32 - int d = _open(name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); - if (d < 0) { free(name); continue; } - if (unlink(name) < 0) { free(name); _close(d); return -1; } - free(name); + tname += "XXXXXX"; + int d = mkstemp((char*)tname.c_str()); + if (d < 0) { continue; } + if (unlink(tname.c_str()) < 0) { _close(d); return -1; } return d; #endif // _WIN32 }