]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
windows: Provide a close(2) that can close both file handles and sockets
authorMartin Willi <martin@revosec.ch>
Thu, 21 Nov 2013 15:27:21 +0000 (16:27 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:53:04 +0000 (15:53 +0200)
src/libstrongswan/utils/windows.c
src/libstrongswan/utils/windows.h

index 48a70b6c29ae7354f5beb8d32b699d0cf8a992f1..492821d53d6ec78d89c95adbbabd0020b3d3e4f1 100644 (file)
@@ -331,6 +331,22 @@ static bool check_dontwait(int *flags)
        return FALSE;
 }
 
+/**
+ * See header
+ */
+#undef close
+int windows_close(int fd)
+{
+       int ret;
+
+       ret = close(fd);
+       if (ret == -1 && errno == EBADF)
+       {       /* Winsock socket? */
+               ret = wserr(closesocket(fd));
+       }
+       return ret;
+}
+
 /**
  * See header
  */
index d57b5dc1d38f6b4cd68d70ce3aed082eca42e14d..3e317ce5920c7000d1258f3a78f6540923c18e95 100644 (file)
@@ -264,6 +264,12 @@ int socketpair(int domain, int type, int protocol, int sv[2]);
  */
 #define ECONNRESET ENXIO
 
+/**
+ * close(2) working for file handles and Winsock sockets
+ */
+#define close windows_close
+int windows_close(int fd);
+
 /**
  * recv(2) with support for MSG_DONTWAIT
  */