diff --git a/NEWS b/NEWS index ef9e8109..51e55c03 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ Version 0.19 ( ) ------------------------------- +- Carlo Bramini fixed the build for msys+mingw. Bug #1943976. + - Neil Gierman provided improved Visual Studio 2008 code in bug #1946268 - Bug #1862727 fixed libssh2_poll() to work on windows (by defining diff --git a/configure.in b/configure.in index c40553ba..39282bff 100644 --- a/configure.in +++ b/configure.in @@ -28,6 +28,10 @@ AB_INIT # get this removed. AC_CANONICAL_HOST case "$host" in + *-mingw*) + CFLAGS="$CFLAGS -DLIBSSH2_WIN32 -DWINSOCK_VERSION=0x0200" + LIBS="$LIBS -lws2_32" + ;; *-cygwin) CFLAGS="$CFLAGS -DLIBSSH2_WIN32" ;; @@ -254,8 +258,31 @@ AC_HELP_STRING([--disable-debug],[Disable debug options]), AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/uio.h]) AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) +AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h]) AC_CHECK_FUNCS(poll gettimeofday select strtoll) +dnl Check for select() into ws2_32 for Msys/Mingw +if test "$ac_cv_func_select" != "yes"; then + AC_MSG_CHECKING([for select in ws2_32]) + AC_TRY_LINK([ +#ifdef HAVE_WINSOCK2_H +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#endif + ],[ + select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL); + ],[ + AC_MSG_RESULT([yes]) + HAVE_SELECT="1" + AC_DEFINE_UNQUOTED(HAVE_SELECT, 1, + [Define to 1 if you have the select function.]) + ],[ + AC_MSG_RESULT([no]) + ]) +fi + AC_FUNC_ALLOCA # Checks for typedefs, structures, and compiler characteristics. diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 20025b1f..45d463aa 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -91,6 +91,41 @@ #include "openssl.h" #endif +#ifdef HAVE_WINSOCK2_H + +#include +#include +#include + +/* same as WSABUF */ +struct iovec { + u_long iov_len; + char *iov_base; +}; + +#ifdef _MSC_VER +/* "inline" keyword is valid only with C++ engine! */ +#define inline __inline +#endif + +static inline int writev(int sock, struct iovec *iov, int nvecs) +{ + DWORD ret; + if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) { + return ret; + } + return -1; +} + +/* not really usleep, but safe for the way we use it in this lib */ +static inline int usleep(int udelay) +{ + Sleep(udelay / 1000); + return 0; +} + +#endif + /* RFC4253 section 6.1 Maximum Packet Length says: * * "All implementations MUST be able to process packets with diff --git a/win32/libssh2_config.h b/win32/libssh2_config.h index 3a8e117e..93d45e45 100644 --- a/win32/libssh2_config.h +++ b/win32/libssh2_config.h @@ -12,36 +12,16 @@ #define HAVE_UNISTD_H #define HAVE_INTTYPES_H #define HAVE_SYS_TIME_H + +/* defined into MS PSDK but not into Mingw w32api */ +#define WINSOCK_VERSION MAKEWORD(2,0) + #endif #define HAVE_WINSOCK2_H #define HAVE_IOCTLSOCKET #define HAVE_SELECT -/* same as WSABUF */ -struct iovec { - u_long iov_len; - char *iov_base; -}; - -#define inline __inline - -static inline int writev(int sock, struct iovec *iov, int nvecs) -{ - DWORD ret; - if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) { - return ret; - } - return -1; -} - -/* not really usleep, but safe for the way we use it in this lib */ -static inline int usleep(int udelay) -{ - Sleep(udelay / 1000); - return 0; -} - #ifdef _MSC_VER #define snprintf _snprintf #if _MSC_VER < 1500 @@ -53,12 +33,8 @@ static inline int usleep(int udelay) #define strncasecmp _strnicmp #define strcasecmp _stricmp #else -#ifdef __MINGW32__ -#define WINSOCK_VERSION MAKEWORD(2,0) -#else #define strncasecmp strnicmp #define strcasecmp stricmp -#endif /* __MINGW32__ */ #endif /* _MSC_VER */ /* Compile in zlib support */