1 #ifndef _WINUIO_H 2 #define _WINUIO_H 3 4 #include <inttypes.h> 5 6 #ifndef _WIN32 7 #include <unistd.h> 8 #else 9 #include <errno.h> 10 #include <io.h> 11 #include <BaseTsd.h> 12 #include <winsock2.h> 13 #include <ws2tcpip.h> 14 typedef SSIZE_T ssize_t; 15 #endif 16 17 struct mk_iovec 18 { 19 void *iov_base; /* Base address of a memory region for input or output */ 20 size_t iov_len; /* The size of the memory pointed to by iov_base */ 21 }; 22 23 /* Long way to go here, it's mostly a placeholder */ 24 25 static inline ssize_t readv(int fildes, const struct mk_iovec *iov, int iovcnt) 26 { 27 errno = ENOSYS; 28 return -1; 29 } 30 31 static inline ssize_t writev(int fildes, const struct mk_iovec *iov, int iovcnt) 32 { 33 int i; 34 uint32_t bytes_written = 0; 35 36 for (i = 0; i < iovcnt; i++) { 37 int len; 38 39 len = send((SOCKET)fildes, iov[i].iov_base, (int)iov[i].iov_len, 0); 40 if (len == SOCKET_ERROR) { 41 uint32_t err = GetLastError(); 42 // errno = win_to_posix_error(err); 43 bytes_written = -1; 44 break; 45 } 46 bytes_written += len; 47 } 48 49 return bytes_written; 50 } 51 52 53 #endif /* _WINUIO_H */ 54 55