diff --git a/configure.ac b/configure.ac index d8b85c4..63455ac 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,7 @@ case $host in AC_CHECK_LIB([socket], [main], , [AC_MSG_ERROR([Can not find required library])]) AC_CHECK_LIB([nsl], [main], , [AC_MSG_ERROR([Can not find required library])]) ;; - *mingw*) + *mingw*|*msys*) target_os_is_win32=true ;; *) @@ -84,6 +84,40 @@ AM_CONDITIONAL([HAVE_LIBGCRYPT], [test $ac_cv_lib_gcrypt_gcry_control = yes]) # For MinGW. AC_CHECK_LIB([ws2_32], [gethostbyname]) +AC_CHECK_HEADERS([sys/select.h]) +AC_CHECK_HEADERS([winsock.h winsock2.h ws2tcpip.h],,,[#include ]) + +# +# Check for the type of the fifth argument of select() since MinGW uses +# struct __ms_timeval. +# + +ac_save_CFLAGS=$CFLAGS +CFLAGS="$CFLAGS -Werror" +AC_MSG_CHECKING([for the type of the fifth argument of select()]) +arg_type=void +for t in "struct timeval" "struct __ms_timeval"; do +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([ +#if defined(HAVE_WINSOCK2_H) && defined(HAVE_WS2TCPIP_H) +#include +#include +#else +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#endif +#include +], [return select(0, NULL, NULL, NULL, ($t *)NULL)])], + [arg_type=$t; break]) +done +AC_MSG_RESULT(${arg_type}) +AC_DEFINE_UNQUOTED([SELECT_TIMEVAL_TYPE], [${arg_type}], + [Type of the fifth argument of select()]) +CFLAGS=$ac_save_CFLAGS + +AC_CHECK_FUNCS([tzset]) + AC_CACHE_CHECK([for sin_len in sock],libiscsi_cv_HAVE_SOCK_SIN_LEN,[ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include #include @@ -104,30 +138,15 @@ if test x"$libiscsi_cv_NEED_SYS_FILIO_H" = x"yes"; then AC_DEFINE(NEED_SYS_FILIO_H,1,[Whether we need sys/filio.h]) fi -# check for sys/socket.h -dnl Check for sys/socket.h -AC_CHECK_HEADERS([sys/socket.h]) - -# check for netinet/tcp.h -dnl Check for netinet/tcp.h -AC_CHECK_HEADERS([netinet/tcp.h]) - -# check for netinet/in.h -dnl Check for netinet/in.h -AC_CHECK_HEADERS([netinet/in.h]) - -# check for arpa/inet.h -dnl Check for arpa/inet.h -AC_CHECK_HEADERS([arpa/inet.h]) - -# check for sys/uio.h -dnl Check for sys/uio.h -AC_CHECK_HEADERS([sys/uio.h]) - -# check for poll.h -dnl Check for poll.h -AC_CHECK_HEADERS([poll.h]) - +AC_CHECK_HEADERS(dnl +[arpa/inet.h] dnl +[netinet/in.h] dnl +[netinet/tcp.h] dnl +[poll.h] dnl +[sys/socket.h] dnl +[sys/time.h] dnl +[sys/uio.h] dnl +) AC_CACHE_CHECK([for sockaddr_in6 support],libiscsi_cv_HAVE_SOCKADDR_IN6,[ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include @@ -179,6 +198,11 @@ if ! test "$ac_cv_have_cunit" = yes ; then fi AM_CONDITIONAL(ISCSITEST, [test "$ac_cv_have_cunit" = yes -a "$enable_shared" = "yes"]) +AC_CHECK_MEMBER([struct timezone.tz_dsttime], + [AC_DEFINE([HAVE_TIMEZONE_TZ_DSTTIME], [1], + [Define this macro if struct timezone has tz_dsttime])], [], + [#include ]) + AC_CHECK_MEMBER([struct CU_SuiteInfo.pSetUpFunc], [AC_DEFINE([HAVE_CU_SUITEINFO_PSETUPFUNC], 1, [Define to 1 if struct CU_SuiteInfo has a member called pSetUpFunc])], diff --git a/examples/Makefile.am b/examples/Makefile.am index fa439ff..0d39978 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS=-I. -I${srcdir}/../include +AM_CPPFLAGS=-I. -I${srcdir}/../include -I${srcdir}/../win32 AM_CFLAGS=$(WARN_CFLAGS) AM_LDFLAGS=-no-undefined LIBS=../lib/libiscsi.la diff --git a/examples/iscsi-dd.c b/examples/iscsi-dd.c index 4c97499..05b31fd 100644 --- a/examples/iscsi-dd.c +++ b/examples/iscsi-dd.c @@ -15,12 +15,17 @@ along with this program; if not, see . */ +#include "config.h" #include #include #include #include #include +#ifdef HAVE_POLL_H #include +#else +#include "win32_compat.h" +#endif #include #include #include diff --git a/examples/iscsiclient.c b/examples/iscsiclient.c index 7bbe06d..2cc60a1 100644 --- a/examples/iscsiclient.c +++ b/examples/iscsiclient.c @@ -37,7 +37,9 @@ #if defined(_WIN32) #include #include "win32/win32_compat.h" +#ifdef _MSC_VER #pragma comment(lib, "ws2_32.lib") +#endif WSADATA wsaData; #else #include diff --git a/lib/Makefile.am b/lib/Makefile.am index ed7ede4..29f5dfd 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -37,6 +37,14 @@ lib_LTLIBRARIES = libiscsi.la libiscsi_la_SOURCES = libiscsi_la_LIBADD = libiscsipriv.la +libiscsi.syms: libiscsi.syms.in + cat <$< >$@ +if TARGET_OS_IS_WIN32 + echo win32_poll >>$@ +endif + +EXTRA_libiscsi_la_DEPENDENCIES = libiscsi.syms + SOCURRENT=9 SOREVISON=0 SOAGE=0 diff --git a/lib/libiscsi.syms b/lib/libiscsi.syms.in similarity index 100% rename from lib/libiscsi.syms rename to lib/libiscsi.syms.in diff --git a/tests/Makefile.am b/tests/Makefile.am index 599033b..0f65562 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I${srcdir}/../include +AM_CPPFLAGS = -I${srcdir}/../include -I${srcdir}/../win32 AM_CFLAGS = $(WARN_CFLAGS) AM_LDFLAGS = -no-undefined LIBS = ../lib/libiscsi.la diff --git a/tests/prog_header_digest.c b/tests/prog_header_digest.c index 357ba9f..fd50d7c 100644 --- a/tests/prog_header_digest.c +++ b/tests/prog_header_digest.c @@ -20,6 +20,8 @@ #ifdef HAVE_POLL_H #include +#else +#include "win32_compat.h" #endif #ifdef HAVE_UNISTD_H diff --git a/tests/prog_noop_reply.c b/tests/prog_noop_reply.c index a844ce2..55aee60 100644 --- a/tests/prog_noop_reply.c +++ b/tests/prog_noop_reply.c @@ -20,6 +20,8 @@ #ifdef HAVE_POLL_H #include +#else +#include "win32_compat.h" #endif #ifdef HAVE_UNISTD_H diff --git a/tests/prog_read_all_pdus.c b/tests/prog_read_all_pdus.c index 2c30d7c..e889e60 100644 --- a/tests/prog_read_all_pdus.c +++ b/tests/prog_read_all_pdus.c @@ -20,6 +20,8 @@ #ifdef HAVE_POLL_H #include +#else +#include "win32_compat.h" #endif #ifdef HAVE_UNISTD_H diff --git a/tests/prog_reconnect.c b/tests/prog_reconnect.c index ba7871f..1f89968 100644 --- a/tests/prog_reconnect.c +++ b/tests/prog_reconnect.c @@ -20,6 +20,8 @@ #ifdef HAVE_POLL_H #include +#else +#include "win32_compat.h" #endif #ifdef HAVE_UNISTD_H diff --git a/tests/prog_reconnect_timeout.c b/tests/prog_reconnect_timeout.c index d6b5881..174e8a5 100644 --- a/tests/prog_reconnect_timeout.c +++ b/tests/prog_reconnect_timeout.c @@ -20,6 +20,8 @@ #ifdef HAVE_POLL_H #include +#else +#include "win32_compat.h" #endif #ifdef HAVE_UNISTD_H diff --git a/utils/Makefile.am b/utils/Makefile.am index 1c2684a..26c0df0 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,8 +1,9 @@ -AM_CPPFLAGS = -I${srcdir}/../include +AM_CPPFLAGS = -I${srcdir}/../include -I${srcdir}/../win32 AM_CFLAGS = $(WARN_CFLAGS) AM_LDFLAGS = -no-undefined LIBS = ../lib/libiscsi.la -bin_PROGRAMS = iscsi-inq iscsi-ls iscsi-perf iscsi-readcapacity16 \ - iscsi-swp - +bin_PROGRAMS = iscsi-inq iscsi-ls iscsi-swp +if !TARGET_OS_IS_WIN32 +bin_PROGRAMS += iscsi-perf iscsi-readcapacity16 +endif diff --git a/utils/iscsi-ls.c b/utils/iscsi-ls.c index dbb7ebc..5649701 100644 --- a/utils/iscsi-ls.c +++ b/utils/iscsi-ls.c @@ -21,7 +21,9 @@ #if defined(_WIN32) #include #include "win32_compat.h" +#ifdef _MSC_VER #pragma comment(lib, "ws2_32.lib") +#endif WSADATA wsaData; #endif diff --git a/win32/win32_compat.c b/win32/win32_compat.c index 40bc4ce..8b2e675 100644 --- a/win32/win32_compat.c +++ b/win32/win32_compat.c @@ -21,10 +21,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" #include "win32_compat.h" #include #include -#include < time.h > +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif #undef poll #undef socket @@ -46,15 +50,13 @@ int win32_inet_pton(int af, const char *src, void *dst) struct sockaddr_in sa; int len = sizeof(SOCKADDR); int ret = -1; - int strLen = strlen(src) + 1; #ifdef UNICODE + int strLen = strlen(src) + 1; wchar_t *srcNonConst = (wchar_t *)malloc(strLen * sizeof(wchar_t)); memset(srcNonConst, 0, strLen); MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen); #else - char *srcNonConst = (char *)malloc(strLen); - memset(srcNonConst, 0, strLen); - strncpy(srcNonConst, src, strLen); + char *srcNonConst = strdup(src); #endif if (WSAStringToAddress(srcNonConst, af, NULL, (LPSOCKADDR)&sa, &len) == @@ -72,7 +74,7 @@ int win32_inet_pton(int af, const char *src, void *dst) int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) { - struct timeval timeout, *toptr; + SELECT_TIMEVAL_TYPE timeout, *toptr; fd_set ifds, ofds, efds, *ip, *op; unsigned int i; int rc; @@ -142,10 +144,12 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL #endif +#ifndef HAVE_TIMEZONE_TZ_DSTTIME struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; +#endif int win32_gettimeofday(struct timeval *tv, struct timezone *tz) { @@ -169,7 +173,11 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz) if (NULL != tz) { if (!tzflag) { +#ifdef HAVE_TZSET + tzset(); +#else _tzset(); +#endif tzflag++; } tz->tz_minuteswest = _timezone / 60; diff --git a/win32/win32_compat.h b/win32/win32_compat.h index 6176636..e04e6cd 100644 --- a/win32/win32_compat.h +++ b/win32/win32_compat.h @@ -25,9 +25,6 @@ THE SOFTWARE. #ifndef win32_COMPAT_H_ #define win32_COMPAT_H_ -#ifdef _WIN32 -#define NO_IPv6 1 - #include #include #include @@ -98,7 +95,6 @@ ssize_t win32_writev(int fd, const struct iovec *iov, int iovcnt); ssize_t win32_readv(int fd, const struct iovec *iov, int iovcnt); int win32_dup2(int oldfd, int newfd); -#define inline +#define inline __inline__ -#endif // _WIN32 #endif // win32_COMPAT_H_