Skip to content

Commit 2207a92

Browse files
committed
Updated included headers to support compilation on Windows (using Visual C++)
- most of posix related functions and constants in unistd.h can be found in io.h in Visual C++ - introduced src/compat/msvc.h to adjust for compiler differences (and avoid updating code with #ifdef blocks for Windows support) - removed some included headers that are not needed (both on Unix and Windows builds)
1 parent 07e5a70 commit 2207a92

File tree

33 files changed

+130
-12
lines changed

33 files changed

+130
-12
lines changed

examples/multiprocess_c/multi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
#include <stdio.h>
2020
#include <stdlib.h>
2121
#include <string.h>
22+
#ifndef WIN32
2223
#include <unistd.h>
24+
#else
25+
#include <io.h>
26+
#endif
2327
#include <sys/types.h>
2428
#include <sys/wait.h>
2529
#include <sys/time.h>

examples/using_bodies_in_chunks/simple_request.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
*
1414
*/
1515

16+
#ifndef WIN32
1617
#include <unistd.h>
18+
#else
19+
#include <io.h>
20+
#endif
1721
#include <stdio.h>
1822
#include <string.h>
1923

src/actions/transformations/html_entity_decode.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "modsecurity/transaction.h"
2828
#include "src/actions/transformations/transformation.h"
2929

30+
#ifdef WIN32
31+
#include "src/compat/msvc.h"
32+
#endif
33+
3034

3135
namespace modsecurity {
3236
namespace actions {

src/actions/transformations/lower_case.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <algorithm>
1919
#include <string>
20+
#include <locale>
2021

2122
#include "modsecurity/transaction.h"
2223
#include "src/actions/transformations/transformation.h"

src/actions/transformations/upper_case.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <algorithm>
1919
#include <string>
20+
#include <locale>
2021

2122
#include "modsecurity/transaction.h"
2223
#include "src/actions/transformations/transformation.h"

src/audit_log/writer/parallel.cc

Lines changed: 5 additions & 0 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 <stdlib.h>
2631

2732
#include <fstream>

src/audit_log/writer/writer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919

2020
#include <stdio.h>
21+
#ifndef WIN32
2122
#include <sys/ipc.h>
2223
#include <sys/shm.h>
24+
#endif
2325
#include <sys/types.h>
2426

2527
#include <iostream>

src/collection/backend/in_memory-per_process.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* directly using the email address [email protected].
1313
*
1414
*/
15+
#include <pthread.h>
1516

1617

1718
#ifdef __cplusplus

src/collection/backend/lmdb.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
#include "src/collection/backend/collection_data.h"
1919

2020
#include <sys/types.h>
21+
#ifndef WIN32
2122
#include <unistd.h>
23+
#else
24+
#include <io.h>
25+
#endif
2226

2327
#include <string>
2428
#include <memory>

src/compat/msvc.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef __COMPAT_MSVC
2+
#define __COMPAT_MSVC
3+
4+
#include <time.h>
5+
6+
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
7+
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
8+
#endif
9+
10+
#define strcasecmp _stricmp
11+
#define strncasecmp _strnicmp
12+
#define strtok_r strtok_s
13+
#define popen _popen
14+
#define pclose _pclose
15+
16+
inline tm* localtime_r(const time_t* tin, tm* tout) {
17+
if (!localtime_s(tout, tin)) return tout;
18+
19+
return nullptr;
20+
}
21+
22+
#endif

0 commit comments

Comments
 (0)