]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
windows: Provide a write(2) wrapper that uses send(2) on sockets
authorMartin Willi <martin@revosec.ch>
Thu, 6 Nov 2014 13:18:22 +0000 (14:18 +0100)
committerMartin Willi <martin@revosec.ch>
Fri, 21 Nov 2014 11:02:08 +0000 (12:02 +0100)
src/libstrongswan/utils/windows.c
src/libstrongswan/utils/windows.h

index e511db02659d7d865197b56bb7d9f831cde1482f..241ad055a453a31f7d4d29cdeea4f04ace7bd7de 100644 (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
  */
index ffd95b3fbc9aa075064dee3b05458ba0eb07cf01..147d3aa2c34fd3c7d1844f34f9539248fb7c1324 100644 (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