1 #ifndef RBX_WINDOWS_COMPAT_H
2 #define RBX_WINDOWS_COMPAT_H
11 char *crypt(const char *, const char *);
16 int map_errno(DWORD winerr
);
18 inline void* dlopen(const char* name
, int mode
) {
19 return LoadLibrary(name
);
22 inline int dlclose(void* handle
) {
23 return !FreeLibrary((HMODULE
)handle
);
26 inline const char* dlerror(void) {
27 return strerror(map_errno(GetLastError()));
30 inline void* dlsym(void* handle
, const char* symbol
) {
31 return (void*)GetProcAddress((HMODULE
)handle
, symbol
);
36 #define RTLD_GLOBAL -1
39 int setenv(const char *name
, const char *value
, int overwrite
);
40 int unsetenv(const char *name
);
42 // Adapted from BSD source code.
43 #define UNAME_NAMELEN 256
46 char sysname
[UNAME_NAMELEN
]; /* Name of OS */
47 char nodename
[UNAME_NAMELEN
]; /* Name of this network node */
48 char release
[UNAME_NAMELEN
]; /* Release level */
49 char version
[UNAME_NAMELEN
]; /* Version level */
50 char machine
[UNAME_NAMELEN
]; /* Hardware type */
53 int uname(struct utsname
*name
);
61 #define SHUT_RD SD_RECEIVE
69 #define SHUT_WR SD_SEND
77 #define SHUT_RDWR SD_BOTH
87 # define EWOULDBLOCK WSAEWOULDBLOCK
90 # define EINPROGRESS WSAEINPROGRESS
93 # define EALREADY WSAEALREADY
96 # define ENOTSOCK WSAENOTSOCK
99 # define EDESTADDRREQ WSAEDESTADDRREQ
102 # define EMSGSIZE WSAEMSGSIZE
105 # define EPROTOTYPE WSAEPROTOTYPE
108 # define ENOPROTOOPT WSAENOPROTOOPT
110 #ifndef EPROTONOSUPPORT
111 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
113 #ifndef ESOCKTNOSUPPORT
114 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
117 # define EOPNOTSUPP WSAEOPNOTSUPP
120 # define EPFNOSUPPORT WSAEPFNOSUPPORT
123 # define EAFNOSUPPORT WSAEAFNOSUPPORT
126 # define EADDRINUSE WSAEADDRINUSE
128 #ifndef EADDRNOTAVAIL
129 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
132 # define ENETDOWN WSAENETDOWN
135 # define ENETUNREACH WSAENETUNREACH
138 # define ENETRESET WSAENETRESET
141 # define ECONNABORTED WSAECONNABORTED
144 # define ECONNRESET WSAECONNRESET
147 # define ENOBUFS WSAENOBUFS
150 # define EISCONN WSAEISCONN
153 # define ENOTCONN WSAENOTCONN
156 # define ESHUTDOWN WSAESHUTDOWN
159 # define ETOOMANYREFS WSAETOOMANYREFS
162 # define ETIMEDOUT WSAETIMEDOUT
165 # define ECONNREFUSED WSAECONNREFUSED
168 # define ELOOP WSAELOOP
171 # define EHOSTDOWN WSAEHOSTDOWN
174 # define EHOSTUNREACH WSAEHOSTUNREACH
177 # define EPROCLIM WSAEPROCLIM
180 # define EUSERS WSAEUSERS
183 # define EDQUOT WSAEDQUOT
186 # define ESTALE WSAESTALE
189 # define EREMOTE WSAEREMOTE
193 int socketpair(int domain
, int type
, int protocol
, int socket_vector
[2]);
194 int pipe(int fildes
[2]);
197 char* realpath(char* file_name
, char* resolved_name
);
200 #define timezone _timezone
202 time_t timegm(struct tm
* tm
);
203 int nanosleep(const struct timespec
*rqtp
, struct timespec
*rmtp
);
206 #define localtime_r(_Time, _Tm) ({ \
207 struct tm *___tmp_tm = localtime((_Time)); \
209 *(_Tm) = *___tmp_tm; \
217 #define gmtime_r(_Time,_Tm) ({ \
218 struct tm *___tmp_tm = gmtime((_Time)); \
220 *(_Tm) = *___tmp_tm; \
227 #define RBX_USEC_PER_SEC 1000000
228 #define timeradd(tvp, uvp, vvp) \
230 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
231 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
232 if ((vvp)->tv_usec >= RBX_USEC_PER_SEC) { \
234 (vvp)->tv_usec -= RBX_USEC_PER_SEC; \
237 #define timersub(tvp, uvp, vvp) \
239 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
240 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
241 if ((vvp)->tv_usec < 0) { \
243 (vvp)->tv_usec += RBX_USEC_PER_SEC; \
251 int fcntl(int fildes
, int cmd
, ...);
253 #endif // RBX_WINDOWS
255 // Keep these ifdef short so they are clear. Each one
256 // defines a Windows and non-Windows alternative.
258 // MinGW defines setjmp in terms of _setjmp.
259 #define set_jump(x) setjmp(x)
260 #define long_jump(x, y) longjmp(x, y)
262 #define set_jump(x) _setjmp(x)
263 #define long_jump(x, y) _longjmp(x, y)
267 typedef unsigned int int_fd_t
;
269 typedef int int_fd_t
;
276 #endif // RBX_WINDOWS_COMPAT_H