Rework LuCI build system
[project/luci.git] / libs / luci-lib-nixio / src / mingw-compat.h
1 #ifndef NIXIO_MINGW_COMPAT_H_
2 #define NIXIO_MINGW_COMPAT_H_
3
4 #include <winsock2.h>
5 #include <ws2tcpip.h>
6 #include <io.h>
7 #include <process.h>
8 #include <stdint.h>
9 #include <sys/stat.h>
10 #include <errno.h>
11
12 typedef unsigned int uint;
13 typedef unsigned long ulong;
14
15 #define S_ISLNK(m) 0
16 #define S_ISSOCK(m) 0
17
18 #define EWOULDBLOCK WSAEWOULDBLOCK
19 #define EAFNOSUPPORT WSAEAFNOSUPPORT
20 #define ENOPROTOOPT WSAENOPROTOOPT
21
22 #define SHUT_RD         SD_RECEIVE
23 #define SHUT_WR         SD_SEND
24 #define SHUT_RDWR       SD_BOTH
25
26 #define pipe(fds) _pipe(fds, 65536, 0)
27 #define fsync _commit
28 #define lseek lseek64
29 #define stat _stati64
30 #define lstat _stati64
31 #define fstat _fstati64
32
33
34 #define F_LOCK 1
35 #define F_ULOCK 0
36 #define F_TLOCK 2
37 #define F_TEST 3
38 int nixio__mgw_lockf(int fd, int cmd, off_t len);
39 #define lockf nixio__mgw_lockf
40
41 const char* nixio__mgw_inet_ntop
42 (int af, const void *src, char *dst, socklen_t size);
43 #define inet_ntop nixio__mgw_inet_ntop
44
45 int nixio__mgw_inet_pton (int af, const char *src, void *dst);
46 #define inet_pton nixio__mgw_inet_pton
47
48
49 #ifndef POLLIN
50 #define POLLIN  0x001
51 #define POLLOUT 0x004
52 #define POLLERR 0x008
53 struct pollfd {
54    int   fd;
55    short events;
56    short revents;
57 };
58 #endif
59
60 typedef int nfds_t;
61 int nixio__mgw_poll(struct pollfd *fds, nfds_t nfds, int timeout);
62 #define poll nixio__mgw_poll
63
64
65 struct timespec {
66       time_t tv_sec;
67       long   tv_nsec;
68 };
69
70 int nixio__mgw_nanosleep(const struct timespec *req, struct timespec *rem);
71 #define nanosleep nixio__mgw_nanosleep
72
73
74 char* nixio__mgw_realpath(const char *path, char *resolved);
75 #define realpath nixio__mgw_realpath
76
77
78 int nixio__mgw_link(const char *oldpath, const char *newpath);
79 #define link nixio__mgw_link
80
81
82 int nixio__mgw_utimes(const char *filename, const struct timeval times[2]);
83 #define utimes nixio__mgw_utimes
84
85
86 #define setenv(k, v, o) !SetEnvironmentVariable(k, v)
87 #define unsetenv(k) !SetEnvironmentVariable(k, NULL)
88
89 #define execv(p, a) execv(p, (const char* const*)a)
90 #define execvp(p, a) execvp(p, (const char* const*)a)
91 #define execve(p, a, e) execve(p, (const char* const*)a, (const char* const*)e)
92
93 #define mkdir(p, m) mkdir(p)
94
95
96 #define nixio__perror_s(L) \
97         errno = WSAGetLastError(); \
98         return nixio__perror(L);
99
100 #define nixio__pstatus_s(L, c) \
101         errno = WSAGetLastError(); \
102         return nixio__pstatus(L, c);
103
104
105
106 #define NIXIO_WSA_CONSTANT(x) \
107         lua_pushinteger(L, x); \
108         lua_setfield(L, -2, #x+3);
109
110 void nixio_open__mingw(lua_State *L);
111
112 #endif /* NIXIO_MINGW_COMPAT_H_ */