1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 #ifndef _UNISTD_H
19 #define _UNISTD_H 1
20 #include <stdio.h>
21 #include <io.h>
22 #define WIN32_LEAN_AND_MEAN
23 #define NOMINMAX
24 #include <windows.h>
25 #include <process.h>
26 #include <winsock2.h>
27 #include <inaddr.h>
28 #include <stdint.h>
29 #include <time.h>
30 #include "inttypes.h"
31 #ifdef __cplusplus
32 #include <string>
33 extern "C" {
34 #endif
35 
36 #if _MSC_VER < 1800
37 extern unsigned long long strtoull(const char*, char**, int);
38 extern long long atoll(const char*);
39 #if _MSC_VER < 1600
40 extern lldiv_t lldiv(const long long, const long long);
41 #endif
42 #endif
43 extern unsigned int sleep(unsigned int);
44 
45 #define strerror_r(e, b, l) strerror_s((b), (l), (e))
46 
47 #ifndef F_OK
48 #define F_OK 00
49 #define W_OK 02
50 #define R_OK 04
51 #define X_OK 00
52 #endif
53 #ifndef F_RDLCK
54 #define F_RDLCK 1
55 #define F_SETLKW 2
56 #define F_UNLCK 3
57 #define F_WRLCK 4
58 #define F_SETLK 5
59 #endif
60 #ifndef LOCK_SH
61 #define LOCK_SH 0
62 #define LOCK_UN 1
63 #define LOCK_EX 2
64 #endif
65 struct flock
66 {
67     int l_type;
68     int l_whence;
69     int l_start;
70     int l_len;
71     int l_pid;
72 };
73 extern int flock(int, int);
74 extern int fcntl(int, int, ...);
75 #ifndef _my_pthread_h
76 struct timespec
77 {
78     long tv_sec;
79     long tv_nsec;
80 };
81 #endif
82 int poll(struct pollfd*, unsigned long, int);
83 #ifndef SHUT_RDWR
84 #define SHUT_RDWR SD_BOTH
85 #endif
86 extern int inet_aton(const char*, struct in_addr*);
87 struct timezone
88 {
89     int  tz_minuteswest; /* minutes W of Greenwich */
90     int  tz_dsttime;     /* type of dst correction */
91 };
92 extern int gettimeofday(struct timeval*, struct timezone*);
93 #define ctime_r(tp, b) ctime_s((b), sizeof(b), (tp))
94 
95 //These are also in MySQL, so we need to fudge them...
96 #ifndef _my_pthread_h
97 #define localtime_r idb_localtime_r
98 extern struct tm* idb_localtime_r(const time_t*, struct tm*);
99 #define strtoll _strtoi64
100 #define strtoull _strtoui64
101 #define crc32 idb_crc32
102 extern unsigned int idb_crc32(const unsigned int, const unsigned char*, const size_t);
103 #endif
104 
105 #define CLOCK_REALTIME 1
106 #define CLOCK_MONOTONIC 2
107 extern long clock_gettime(clockid_t, struct timespec*);
108 
109 extern int syslog(int, const char*, ...);
110 #ifdef __cplusplus
111 extern int closelog(...);
112 extern int openlog(...);
113 #else
114 extern int closelog();
115 extern int openlog();
116 #endif
117 extern int usleep(unsigned int);
118 extern int fork();
119 
120 extern int getpagesize();
121 
122 extern int pipe(int[2]);
123 extern pid_t getppid();
124 extern pid_t waitpid(pid_t, int*, int);
125 
126 #define WIFEXITED(x) 0
127 #define WEXITSTATUS(x) 0
128 #define WIFSIGNALED(x) 0
129 #define WTERMSIG(x) 0
130 
131 #define WNOHANG 0x01
132 #define WUNTRACED 0x02
133 #define WCONTINUED 0x04
134 
135 extern int kill(pid_t, int);
136 extern int setuid(uid_t);
137 
138 #define snprintf _snprintf
139 
140 #ifdef __cplusplus
141 }
142 
143 extern int getopt(int argc, char* const* argv, const char* optstring);
144 extern char* optarg;
145 extern int optind;
146 extern int opterr;
147 extern int optopt;
148 
149 extern std::string IDBSysErrorStr(DWORD err);
150 
151 #endif
152 
153 #endif
154 
155