• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #ifndef __linux__
4 // Make sure these are defined and don't change anything if used.
5 enum {
6     SOCK_CLOEXEC = 0,
7 #ifndef __APPLE__
8     O_CLOEXEC = 0
9 #endif
10 };
11 #endif  // !__linux__
12 
13 #ifdef _MSC_VER
14 
15 #include <windows.h>
16 #include <BaseTsd.h>
17 
18 #include <direct.h>
19 #include <fcntl.h>
20 #include <io.h>
21 #include <process.h>
22 #include <stdint.h>
23 #include <sys/stat.h>
24 #include <time.h>
25 #include <winsock.h>
26 
27 typedef SSIZE_T ssize_t;
28 
29 typedef int mode_t;
30 #ifdef _WIN64
31 typedef int64_t pid_t;
32 #else
33 typedef int pid_t;
34 #endif
35 #define STDIN_FILENO _fileno(stdin)
36 #define STDOUT_FILENO _fileno(stdout)
37 #define STDERR_FILENO _fileno(stderr)
38 #define lseek(a, b, c) _lseek(a, b, c)
39 #define lseek64 _lseeki64
40 
41 struct FileTime {
42   uint32_t dwLowDateTime;
43   uint32_t dwHighDateTime;
44 };
45 
46 // Need <dirent.h>
47 
48 // Define for convenience only in mingw. This is
49 // convenient for the _access function in Windows.
50 #define F_OK 0 /* Check for file existence */
51 #define X_OK 1 /* Check for execute permission (not supported in Windows) */
52 #define W_OK 2 /* Check for write permission */
53 #define R_OK 4 /* Check for read permission */
54 
55 typedef int mode_t;
56 #ifdef _WIN64
57 typedef int64_t pid_t;
58 #else
59 typedef int pid_t;
60 #endif
61 #define STDIN_FILENO _fileno(stdin)
62 #define STDOUT_FILENO _fileno(stdout)
63 #define STDERR_FILENO _fileno(stderr)
64 #define lseek(a, b, c) _lseek(a, b, c)
65 #define lseek64 _lseeki64
66 
67 // These functions were deprecated and replaced with ISO C++ conformant ones
68 // in MSVC 2017.
69 /*
70 #define strdup _strdup
71 #define mkdir _mkdir
72 #define rmdir _rmdir
73 #define getcwd _getcwd
74 #define getpid _getpid
75 #define close _close
76 #define open _open
77 #define read _read
78 #define write _write
79 #define creat _creat
80 */
81 
82 // From <fcntl.h>
83 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
84 
85 // From <sys/types.h>
86 typedef int64_t off64_t;
87 
88 // From <sys/cdefs.h>
89 #ifdef __cplusplus
90 #define __BEGIN_DECLS extern "C" {
91 #define __END_DECLS }
92 #else
93 #define __BEGIN_DECLS /* empty */
94 #define __END_DECLS   /* empty */
95 #endif
96 
97 
98 typedef  void (*SystemTime)(FileTime*);
99 
100 // From <sys/time.h>
101 struct timezone {
102     int tz_minuteswest; /* of Greenwich */
103     int tz_dsttime;     /* type of dst correction to apply */
104 };
105 
106 // From <strings.h>
107 #define strcasecmp _stricmp
108 #define strncasecmp _strnicmp
109 
110 // From <stdio.h>
111 #define fseeko64 _fseeki64
112 #define ftello64 _ftelli64
113 
114 // From <linux/limits.h>
115 #define PATH_MAX MAX_PATH
116 
117 __BEGIN_DECLS
118 
119 
120 extern SystemTime getSystemTime;
121 extern int gettimeofday(struct timeval* tp, struct timezone* tz);
122 extern int asprintf(char** buf, const char* format, ...);
123 extern int vasprintf(char** buf, const char* format, va_list args);
124 extern int mkstemp(char* t);
125 
126 __END_DECLS
127 
128 #endif
129