4 #define WIN32_LEAN_AND_MEAN
12 #define ECONNABORTED WSAECONNABORTED
13 #define EMSGSIZE WSAEMSGSIZE
14 #define EINPROGRESS WSAEWOULDBLOCK // WSAEINPROGRESS
17 #define EAGAIN WSAEWOULDBLOCK // WSAEAGAIN
19 /* dummy types / functions */
22 #define hstrerror strerror
23 #define getuid() (6667)
24 #define setsid() getpid()
25 #define setgid(x) (-1)
26 #define setuid(x) (-1)
28 #define geteuid() getuid()
29 #define setgroups(s, p) (-1)
31 #define srandom(s) srand(s)
32 #define random() rand()
43 #define in_addr_t uint32_t
46 * make recvmsg/sendmsg and fd related code compile
50 void *iov_base
; /* Base address. */
51 size_t iov_len
; /* Length. */
56 socklen_t msg_namelen
;
57 struct iovec
*msg_iov
;
60 socklen_t msg_controllen
;
73 #define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
74 #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
75 & ~(sizeof (size_t) - 1))
76 #define CMSG_LEN(len) ((int)(CMSG_ALIGN(sizeof(struct cmsghdr))+(len)))
77 #define CMSG_FIRSTHDR(mhdr) \
78 ((mhdr)->msg_controllen >= (int)sizeof(struct cmsghdr) ? \
79 (struct cmsghdr *)(mhdr)->msg_control : \
80 (struct cmsghdr *)NULL)
81 #define CMSG_NXTHDR(mhdr, cmsg) \
82 (((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
83 (((u_char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len) \
84 + CMSG_ALIGN(sizeof(struct cmsghdr)) > \
85 (u_char *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
86 (struct cmsghdr *)NULL : \
87 (struct cmsghdr *)((u_char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len))))
88 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr))+CMSG_ALIGN(len))
91 * unify WSAGetLastError() with errno.
94 static inline int ewrap(int res
) {
96 errno
= WSAGetLastError();
100 /* proper signature for setsockopt */
101 static inline int w_setsockopt(int fd
, int level
, int optname
, const void *optval
, socklen_t optlen
)
103 return ewrap(setsockopt(fd
, level
, optname
, optval
, optlen
));
105 #define setsockopt(a,b,c,d,e) w_setsockopt(a,b,c,d,e)
107 #define getsockopt(a,b,c,d,e) ewrap(getsockopt(a,b,c,d,e))
108 #define connect(a,b,c) ewrap(connect(a,b,c))
109 #define recv(a,b,c,d) ewrap(recv(a,b,c,d))
110 #define send(a,b,c,d) ewrap(send(a,b,c,d))
111 #define socket(a,b,c) ewrap(socket(a,b,c))
112 #define bind(a,b,c) ewrap(bind(a,b,c))
113 #define listen(a,b) ewrap(listen(a,b))
114 #define accept(a,b,c) ewrap(accept(a,b,c))
115 #define getpeername(a,b,c) ewrap(getpeername(a,b,c))
116 #define getsockname(a,b,c) ewrap(getsockname(a,b,c))
117 #define select(a,b,c,d,e) ewrap(select(a,b,c,d,e))
119 static inline struct hostent
*w_gethostbyname(const char *n
) {
120 struct hostent
*res
= gethostbyname(n
);
121 if (!res
) errno
= WSAGetLastError();
124 #define gethostbyname(a) w_gethostbyname(a)
126 const char *win32_strerror(int e
);
128 static inline const char *w_strerror(int e
) {
130 return win32_strerror(e
);
133 #define strerror(x) w_strerror(x)
136 /* gettimeoutday() */
137 static inline int win32_gettimeofday(struct timeval
* tp
, void * tzp
)
140 SYSTEMTIME system_time
;
141 ULARGE_INTEGER ularge
;
142 __int64 epoch
= 116444736000000000LL;
144 GetSystemTime(&system_time
);
145 SystemTimeToFileTime(&system_time
, &file_time
);
146 ularge
.LowPart
= file_time
.dwLowDateTime
;
147 ularge
.HighPart
= file_time
.dwHighDateTime
;
149 tp
->tv_sec
= (long) ((ularge
.QuadPart
- epoch
) / 10000000L);
150 tp
->tv_usec
= (long) (system_time
.wMilliseconds
* 1000);
154 #define gettimeofday win32_gettimeofday
156 /* make unix socket related code compile */
163 #define RLIMIT_NOFILE -1
168 static inline int getrlimit(int res
, struct rlimit
*dst
)
170 dst
->rlim_cur
= dst
->rlim_max
= -1;
174 /* kill is only used to detect if process is running (ESRCH->not) */
175 static inline int kill(int pid
, int sig
)
186 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, pid
);
187 if (hProcess
== NULL
) {
188 if (GetLastError() == ERROR_INVALID_PARAMETER
)
193 /* OpenProcess may succed for exited processes */
194 if (GetExitCodeProcess(hProcess
, &exitCode
)) {
195 if (exitCode
!= STILL_ACTIVE
)
198 CloseHandle(hProcess
);
208 /* sendmsg is not used */
209 static inline int sendmsg(int s
, const struct msghdr
*m
, int flags
)
211 if (m
->msg_iovlen
!= 1) {
215 return send(s
, m
->msg_iov
[0].iov_base
,
216 m
->msg_iov
[0].iov_len
, flags
);
219 /* recvmsg() is, but only with one iov */
220 static inline int recvmsg(int s
, struct msghdr
*m
, int flags
)
222 if (m
->msg_iovlen
!= 1) {
226 if (m
->msg_controllen
)
227 m
->msg_controllen
= 0;
228 return recv(s
, m
->msg_iov
[0].iov_base
,
229 m
->msg_iov
[0].iov_len
, flags
);
232 /* dummy getpwnam() */
239 static inline const struct passwd
* getpwnam(const char *u
) { return NULL
; }
250 #define FD_CLOEXEC HANDLE_FLAG_INHERIT
252 static inline int fcntl(int fd
, int cmd
, long arg
)
258 if (GetHandleInformation((HANDLE
)fd
, &dval
))
264 if (SetHandleInformation((HANDLE
)fd
, FD_CLOEXEC
, arg
))
273 lval
= (arg
& O_NONBLOCK
) ? 1 : 0;
274 if (ioctlsocket(fd
, FIONBIO
, &lval
) == SOCKET_ERROR
) {
275 errno
= WSAGetLastError();
293 #define LOG_WARNING 4
310 #define LOG_AUTHPRIV 0
321 static inline void openlog(const char *ident
, int option
, int facility
) {}
322 static inline void closelog(void) {}
323 void win32_eventlog(int priority
, const char *format
, ...);
324 #define syslog win32_eventlog
326 /* redirect main() */
327 #define main(a,b) real_main(a,b)
328 int real_main(int argc
, char *argv
[]);
330 #endif /* _CONFIG_WIN32_ */