From b097ea39f391f5c2c83d8f4687843a3634f7cd54 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sat, 3 Aug 2019 02:43:10 +0800 Subject: win32: Fix compilation --- common/socket.c | 3 +++ tools/icat.c | 20 ++++++++++++++++++-- tools/iproxy.c | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/common/socket.c b/common/socket.c index 0ee8105..777b23e 100644 --- a/common/socket.c +++ b/common/socket.c @@ -52,6 +52,9 @@ static int wsa_init = 0; #ifndef ECONNRESET #define ECONNRESET 108 #endif +#ifndef ETIMEDOUT +#define ETIMEDOUT 138 +#endif static int verbose = 0; diff --git a/tools/icat.c b/tools/icat.c index 9296a23..42f7420 100644 --- a/tools/icat.c +++ b/tools/icat.c @@ -29,19 +29,35 @@ #include #include #include +#ifdef WIN32 +#include +#include +#else #include #include #include +#endif #include "usbmuxd.h" +#include "socket.h" static size_t read_data_socket(int fd, uint8_t* buf, size_t bufsize) { - size_t bytesavailable; +#ifdef WIN32 + u_long bytesavailable = 0; + if (fd == STDIN_FILENO) { + bytesavailable = bufsize; + } else if (ioctlsocket(fd, FIONREAD, &bytesavailable) != 0) { + perror("ioctlsocket FIONREAD failed"); + exit(1); + } +#else + size_t bytesavailable = 0; if (ioctl(fd, FIONREAD, &bytesavailable) != 0) { perror("ioctl FIONREAD failed"); exit(1); } +#endif size_t bufread = (bytesavailable >= bufsize) ? bufsize:bytesavailable; ssize_t ret = read(fd, buf, bufread); if (ret < 0) { @@ -143,6 +159,6 @@ int main(int argc, char **argv) } } - close(devfd); + socket_close(devfd); return ret; } diff --git a/tools/iproxy.c b/tools/iproxy.c index 113938e..a018cf7 100644 --- a/tools/iproxy.c +++ b/tools/iproxy.c @@ -44,6 +44,10 @@ typedef unsigned int socklen_t; #include "socket.h" #include "usbmuxd.h" +#ifndef ETIMEDOUT +#define ETIMEDOUT 138 +#endif + static uint16_t listen_port = 0; static uint16_t device_port = 0; static char* device_udid = NULL; -- cgit v1.1-32-gdbae