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