1 #ifndef foowincompatfoo
2 #define foowincompatfoo
4 // This file and its companion wincompat.c provide some Posix interfaces to
5 // Windows APIs so the rest of the code can keep using them.
8 // require at least Windows Vista
12 #define _WIN32_WINNT WINVER
19 // Winsock doesn't have recvmsg/sendmsg but offers the same functionality
20 // with WSARecvMsg/WSASendMsg, so we implement the former in terms of the
23 struct iovec { /* Scatter/gather array items */
24 void *iov_base; /* Starting address */
25 size_t iov_len; /* Number of bytes to transfer */
29 void *msg_name; /* optional address */
30 socklen_t msg_namelen; /* size of address */
31 struct iovec *msg_iov; /* scatter/gather array */
32 size_t msg_iovlen; /* # elements in msg_iov */
33 void *msg_control; /* ancillary data, see below */
34 size_t msg_controllen; /* ancillary data buffer len */
35 int msg_flags; /* flags on received message */
38 // MSDN says this struct is called wsacmsghdr but MingW uses _WSACMSGHDR.
39 // TODO: Verify what it is on actual Windows.
40 // cf. http://msdn.microsoft.com/en-us/library/ms741645(v=vs.85).aspx
42 #define cmsghdr _WSACMSGHDR // as in 'struct cmsghdr'
44 #define cmsghdr wsacmsghdr // as in 'struct cmsghdr'
47 static inline struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *m) {
49 wm.Control.len = m->msg_controllen;
50 wm.Control.buf = m->msg_control;
51 return WSA_CMSG_FIRSTHDR(&wm);
54 static inline struct cmsghdr *CMSG_NXTHDR(struct msghdr *m, struct cmsghdr *c) {
56 wm.Control.len = m->msg_controllen;
57 wm.Control.buf = m->msg_control;
58 return WSA_CMSG_NXTHDR(&wm, c);
61 #define CMSG_SPACE(len) WSA_CMSG_SPACE(len)
62 #define CMSG_LEN(len) WSA_CMSG_LEN(len)
64 // we're going to be naughty and redefine CMSG_DATA as an alias even though it
65 // is also a constant defined in wincrypt.h which we don't care about.
67 #define CMSG_DATA(c) WSA_CMSG_DATA(c)
69 ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
70 ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
73 // Windows logically doesn't have uname, so we supply a replacement.
76 char sysname[9]; /* Operating system name (e.g., "Linux") */
77 char nodename[MAX_COMPUTERNAME_LENGTH+1];
78 /* Name within "some implementation-defined network" */
79 char release[9]; /* Operating system release (e.g., "2.6.28") */
80 char version[9]; /* Operating system version */
81 char machine[9]; /* Hardware identifier */
84 int uname(struct utsname *buf);