diff options
author | Nikias Bassen | 2019-08-03 02:43:10 +0800 |
---|---|---|
committer | Nikias Bassen | 2019-08-03 02:43:10 +0800 |
commit | b097ea39f391f5c2c83d8f4687843a3634f7cd54 (patch) | |
tree | 589dbb7cb277c2cf3b7b652d32d129892fd00a34 /tools/icat.c | |
parent | 219e6bcae2ab93cd98bd352b62fb0f9d21051344 (diff) | |
download | libusbmuxd-b097ea39f391f5c2c83d8f4687843a3634f7cd54.tar.gz libusbmuxd-b097ea39f391f5c2c83d8f4687843a3634f7cd54.tar.bz2 |
win32: Fix compilation
Diffstat (limited to 'tools/icat.c')
-rw-r--r-- | tools/icat.c | 20 |
1 files changed, 18 insertions, 2 deletions
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 <stddef.h> #include <unistd.h> #include <errno.h> +#ifdef WIN32 +#include <windows.h> +#include <winsock2.h> +#else #include <sys/socket.h> #include <sys/un.h> #include <sys/ioctl.h> +#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; } |