From: Martin Willi Date: Thu, 21 Nov 2013 15:27:21 +0000 (+0100) Subject: windows: Provide a close(2) that can close both file handles and sockets X-Git-Tag: 5.2.0dr6~24^2~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efcf249aebe395e196237e87bd34232f84559112;p=thirdparty%2Fstrongswan.git windows: Provide a close(2) that can close both file handles and sockets --- diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c index 48a70b6c29..492821d53d 100644 --- a/src/libstrongswan/utils/windows.c +++ b/src/libstrongswan/utils/windows.c @@ -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 */ diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index d57b5dc1d3..3e317ce592 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -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 */