Skip to content

Commit 373633f

Browse files
committed
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.
1 parent 3594917 commit 373633f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/request_body_processor/multipart.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
#include <sys/types.h>
2222
#include <sys/stat.h>
2323
#include <fcntl.h>
24+
#ifndef WIN32
2425
#include <unistd.h>
26+
#else
27+
#include <io.h>
28+
#include "src/compat/msvc.h"
29+
#endif
2530
#include <list>
2631
#include <iostream>
2732
#include <string>
@@ -61,27 +66,35 @@ MultipartPartTmpFile::~MultipartPartTmpFile() {
6166

6267
void MultipartPartTmpFile::Open() {
6368
struct tm timeinfo;
64-
char tstr[300];
6569
time_t tt = time(NULL);
6670

6771
localtime_r(&tt, &timeinfo);
6872

69-
memset(tstr, '\0', 300);
73+
char tstr[300] {};
7074
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
7175

7276
std::string path = m_transaction->m_rules->m_uploadDirectory.m_value;
7377
path = path + tstr + "-" + *m_transaction->m_id.get();
7478
path += "-file-XXXXXX";
7579

7680
char* tmp = strdup(path.c_str());
81+
#ifndef WIN32
7782
m_tmp_file_fd = mkstemp(tmp);
83+
#else
84+
_mktemp_s(tmp, path.length()+1);
85+
m_tmp_file_fd = _open(tmp, _O_CREAT | _O_EXCL | _O_RDWR);
86+
#endif
7887
m_tmp_file_name.assign(tmp);
7988
free(tmp);
8089
ms_dbg_a(m_transaction, 4, "MultipartPartTmpFile: Create filename= " + m_tmp_file_name);
8190

8291
int mode = m_transaction->m_rules->m_uploadFileMode.m_value;
8392
if ((m_tmp_file_fd != -1) && (mode != 0)) {
93+
#ifndef WIN32
8494
if (fchmod(m_tmp_file_fd, mode) == -1) {
95+
#else
96+
if (_chmod(m_tmp_file_name.c_str(), mode) == -1) {
97+
#endif
8598
m_tmp_file_fd = -1;
8699
}
87100
}

0 commit comments

Comments
 (0)