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; } }