From 373633ffe2ae754973ce8b34373b9ee16bd359b8 Mon Sep 17 00:00:00 2001 From: Eduardo Arias Date: Wed, 24 Apr 2024 11:01:32 -0300 Subject: [PATCH] mkstemp is not available in Windows build, replaced with _mktemp_s plus _open. - Updated included headers to support compilation on Windows (using Visual C++) - Minor change to use C++ default (zero) initialization instead of calling memset. --- src/request_body_processor/multipart.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/request_body_processor/multipart.cc b/src/request_body_processor/multipart.cc index 691a6fd3..d9ed6c6d 100644 --- a/src/request_body_processor/multipart.cc +++ b/src/request_body_processor/multipart.cc @@ -21,7 +21,12 @@ #include #include #include +#ifndef WIN32 #include +#else +#include +#include "src/compat/msvc.h" +#endif #include #include #include @@ -61,12 +66,11 @@ MultipartPartTmpFile::~MultipartPartTmpFile() { void MultipartPartTmpFile::Open() { struct tm timeinfo; - char tstr[300]; time_t tt = time(NULL); localtime_r(&tt, &timeinfo); - memset(tstr, '\0', 300); + char tstr[300] {}; strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo); std::string path = m_transaction->m_rules->m_uploadDirectory.m_value; @@ -74,14 +78,23 @@ void MultipartPartTmpFile::Open() { path += "-file-XXXXXX"; char* tmp = strdup(path.c_str()); +#ifndef WIN32 m_tmp_file_fd = mkstemp(tmp); +#else + _mktemp_s(tmp, path.length()+1); + m_tmp_file_fd = _open(tmp, _O_CREAT | _O_EXCL | _O_RDWR); +#endif m_tmp_file_name.assign(tmp); free(tmp); ms_dbg_a(m_transaction, 4, "MultipartPartTmpFile: Create filename= " + m_tmp_file_name); int mode = m_transaction->m_rules->m_uploadFileMode.m_value; if ((m_tmp_file_fd != -1) && (mode != 0)) { +#ifndef WIN32 if (fchmod(m_tmp_file_fd, mode) == -1) { +#else + if (_chmod(m_tmp_file_name.c_str(), mode) == -1) { +#endif m_tmp_file_fd = -1; } }