From 0197a589691274055e3a6f47a3652a6714d676bc Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sun, 18 Oct 2015 09:28:10 -0500 Subject: [PATCH] Windows compatibility fixes VS2013 has trouble with relative include paths for apps/openssl, so move certhash_win/apps_win.c back to apps/openssl. gmtime_r on mingw64 fails with negative time_t, override gmtime_s fails all of the time unit tests, override SHUT_RD/WR are defined in newer mingw64 headers, check before overriding --- .gitignore | 2 ++ apps/CMakeLists.txt | 5 ++--- apps/openssl/Makefile.am | 4 ++-- apps/openssl/{compat => }/apps_win.c | 2 +- apps/openssl/{compat => }/certhash_win.c | 0 crypto/compat/timegm.c | 12 ++++++++++++ include/compat/time.h | 6 +++++- include/compat/win32netcompat.h | 15 ++++++++++----- update.sh | 1 - 9 files changed, 34 insertions(+), 13 deletions(-) rename apps/openssl/{compat => }/apps_win.c (98%) rename apps/openssl/{compat => }/certhash_win.c (100%) diff --git a/.gitignore b/.gitignore index 03ed14a..83f8f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,8 @@ include/openssl/*.h /apps/nc/*.h /apps/nc/*.c /apps/nc/nc* +!/apps/openssl/apps_win.c +!/apps/openssl/certhash_win.c /apps/openssl/*.h /apps/openssl/*.c /apps/openssl/*.cnf diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 08bce42..6213aeb 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -2,7 +2,6 @@ include_directories( . ../include ../include/compat - ./openssl ) set( @@ -63,8 +62,8 @@ if(CMAKE_HOST_UNIX) endif() if(CMAKE_HOST_WIN32) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/compat/apps_win.c) - set(OPENSSL_SRC ${OPENSSL_SRC} openssl/compat/certhash_win.c) + set(OPENSSL_SRC ${OPENSSL_SRC} openssl/apps_win.c) + set(OPENSSL_SRC ${OPENSSL_SRC} openssl/certhash_win.c) set(OPENSSL_SRC ${OPENSSL_SRC} openssl/compat/poll_win.c) endif() diff --git a/apps/openssl/Makefile.am b/apps/openssl/Makefile.am index 5a8d458..6ec3d62 100644 --- a/apps/openssl/Makefile.am +++ b/apps/openssl/Makefile.am @@ -60,11 +60,11 @@ openssl_SOURCES += x509.c if BUILD_CERTHASH openssl_SOURCES += certhash.c else -openssl_SOURCES += compat/certhash_win.c +openssl_SOURCES += certhash_win.c endif if HOST_WIN -openssl_SOURCES += compat/apps_win.c +openssl_SOURCES += apps_win.c else openssl_SOURCES += apps_posix.c endif diff --git a/apps/openssl/compat/apps_win.c b/apps/openssl/apps_win.c similarity index 98% rename from apps/openssl/compat/apps_win.c rename to apps/openssl/apps_win.c index bc999f6..37bfcc9 100644 --- a/apps/openssl/compat/apps_win.c +++ b/apps/openssl/apps_win.c @@ -10,7 +10,7 @@ #include #include -#include +#include "apps.h" double app_tminterval(int stop, int usertime) diff --git a/apps/openssl/compat/certhash_win.c b/apps/openssl/certhash_win.c similarity index 100% rename from apps/openssl/compat/certhash_win.c rename to apps/openssl/certhash_win.c diff --git a/crypto/compat/timegm.c b/crypto/compat/timegm.c index 0655ce0..5a9e600 100644 --- a/crypto/compat/timegm.c +++ b/crypto/compat/timegm.c @@ -188,6 +188,18 @@ static int __secs_to_tm(long long t, struct tm *tm) return 0; } +#ifdef _WIN32 +struct tm *__gmtime_r(const time_t *t, struct tm *tm) +{ + if (__secs_to_tm(*t, tm) < 0) { + errno = EOVERFLOW; + return 0; + } + tm->tm_isdst = 0; + return tm; +} +#endif + time_t timegm(struct tm *tm) { struct tm new; diff --git a/include/compat/time.h b/include/compat/time.h index 9ed9c03..99a2001 100644 --- a/include/compat/time.h +++ b/include/compat/time.h @@ -9,11 +9,15 @@ #else #include <../include/time.h> #endif -#define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tm) : NULL) #else #include_next #endif +#ifdef _WIN32 +struct tm *__gmtime_r(const time_t * t, struct tm * tm); +#define gmtime_r(tp, tm) __gmtime_r(tp, tm) +#endif + #ifndef HAVE_TIMEGM time_t timegm(struct tm *tm); #endif diff --git a/include/compat/win32netcompat.h b/include/compat/win32netcompat.h index 452cfba..933f083 100644 --- a/include/compat/win32netcompat.h +++ b/include/compat/win32netcompat.h @@ -11,14 +11,19 @@ #ifdef _WIN32 #include - -#define SHUT_RDWR SD_BOTH -#define SHUT_RD SD_RECEIVE -#define SHUT_WR SD_SEND - #include #include +#ifndef SHUT_RDWR +#define SHUT_RDWR SD_BOTH +#endif +#ifndef SHUT_RD +#define SHUT_RD SD_RECEIVE +#endif +#ifndef SHUT_WR +#define SHUT_WR SD_SEND +#endif + int posix_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); int posix_close(int fd); diff --git a/update.sh b/update.sh index aef190e..de9f2bb 100755 --- a/update.sh +++ b/update.sh @@ -223,7 +223,6 @@ done # copy openssl(1) source echo "copying openssl(1) source" $CP $app_src/openssl/openssl.1 apps/openssl -rm -f apps/openssl/*.c apps/openssl/*.h $CP_LIBC $libc_src/stdlib/strtonum.c apps/openssl/compat $CP $libcrypto_src/cert.pem apps/openssl $CP $libcrypto_src/openssl.cnf apps/openssl