windows: Provide a write(2) wrapper that uses send(2) on sockets

This commit is contained in:
Martin Willi 2014-11-06 14:18:22 +01:00
parent 09624c6cec
commit a301a9c939
2 changed files with 22 additions and 0 deletions

View File

@ -659,6 +659,22 @@ ssize_t windows_read(int fd, void *buf, size_t count)
return ret;
}
/**
* See header
*/
#undef write
ssize_t windows_write(int fd, void *buf, size_t count)
{
ssize_t ret;
ret = send(fd, buf, count, 0);
if (ret == -1 && WSAGetLastError() == WSAENOTSOCK)
{
ret = write(fd, buf, count);
}
return ret;
}
/**
* See header
*/

View File

@ -371,6 +371,12 @@ ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
#define read windows_read
ssize_t windows_read(int fd, void *buf, size_t count);
/**
* write(2) working on files and sockets
*/
#define write windows_write
ssize_t windows_write(int fd, void *buf, size_t count);
#if _WIN32_WINNT < 0x0600
/**
* Define pollfd and flags on our own if not specified