Fix Windows cross-compilation.

Test with: ./configure --host=i686-w64-mingw32
This commit is contained in:
Sam Hocevar 2016-02-08 09:20:55 +01:00
parent a259a67e2d
commit cb60037d58
2 changed files with 25 additions and 22 deletions

View File

@ -11,6 +11,7 @@ AC_PROG_CC
AC_PROG_INSTALL AC_PROG_INSTALL
# Checks for libraries. # Checks for libraries.
AC_CHECK_LIB(ws2_32, main, [LIBS="${LIBS} -lws2_32"])
# Checks for header files. # Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
@ -26,7 +27,8 @@ AC_CHECK_TYPES(socklen_t, [], [],
# Checks for library functions. # Checks for library functions.
AC_FUNC_FORK AC_FUNC_FORK
AC_FUNC_MALLOC #XXX: disabled because of cross-compilation issues
#AC_FUNC_MALLOC
AC_TYPE_SIGNAL AC_TYPE_SIGNAL
AC_FUNC_STRFTIME AC_FUNC_STRFTIME
AC_CHECK_FUNCS([gethostbyname memset select socket strstr daemon fork sigaction]) AC_CHECK_FUNCS([gethostbyname memset select socket strstr daemon fork sigaction])

View File

@ -6,12 +6,13 @@
# define RETSIGTYPE void # define RETSIGTYPE void
#endif #endif
#if WIN32 #if _WIN32
# include <windows.h> # include <windows.h>
# include <winsock.h> # include <winsock.h>
# include "getopt.h" # include "getopt.h"
# define syslog fprintf # define syslog fprintf
# define LOG_ERR stderr # define LOG_ERR stderr
# define LOG_INFO stdout
#else #else
# include <sys/types.h> # include <sys/types.h>
# include <sys/socket.h> # include <sys/socket.h>
@ -30,20 +31,20 @@
# elif HAVE_SYS_TIME_H # elif HAVE_SYS_TIME_H
# include <sys/time.h> # include <sys/time.h>
# endif # endif
#endif /* WIN32 */ #endif /* _WIN32 */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#if WIN32 || (!TIME_WITH_SYS_TIME && !HAVE_SYS_TIME_H) #if _WIN32 || (!TIME_WITH_SYS_TIME && !HAVE_SYS_TIME_H)
# include <time.h> # include <time.h>
#endif #endif
#include <ctype.h> #include <ctype.h>
#if WIN32 #if _WIN32
/* WIN32 doesn't really have WSAEAGAIN */ /* _WIN32 doesn't really have WSAEAGAIN */
# ifndef WSAEAGAIN # ifndef WSAEAGAIN
# define WSAEAGAIN WSAEWOULDBLOCK # define WSAEAGAIN WSAEWOULDBLOCK
# endif # endif
@ -63,7 +64,7 @@ static inline int closesocket(int s) {
static inline int GetLastError(void) { static inline int GetLastError(void) {
return errno; return errno;
} }
#endif /* WIN32 */ #endif /* _WIN32 */
#ifdef DEBUG #ifdef DEBUG
# define PERROR perror # define PERROR perror
@ -148,10 +149,10 @@ static void logEvent(ConnectionInfo const *cnx, ServerInfo const *srv, int resul
static struct tm *get_gmtoff(int *tz); static struct tm *get_gmtoff(int *tz);
/* Signal handlers */ /* Signal handlers */
#if !HAVE_SIGACTION && !WIN32 #if !HAVE_SIGACTION && !_WIN32
static RETSIGTYPE plumber(int s); static RETSIGTYPE plumber(int s);
#endif #endif
#if !WIN32 #if !_WIN32
static RETSIGTYPE hup(int s); static RETSIGTYPE hup(int s);
#endif #endif
static RETSIGTYPE quit(int s); static RETSIGTYPE quit(int s);
@ -159,7 +160,7 @@ static RETSIGTYPE quit(int s);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef WIN32 #ifdef _WIN32
WSADATA wsaData; WSADATA wsaData;
int result = WSAStartup(MAKEWORD(1, 1), &wsaData); int result = WSAStartup(MAKEWORD(1, 1), &wsaData);
if (result != 0) { if (result != 0) {
@ -194,7 +195,7 @@ int main(int argc, char *argv[])
sigaction(SIGPIPE, &act, NULL); sigaction(SIGPIPE, &act, NULL);
act.sa_handler = &hup; act.sa_handler = &hup;
sigaction(SIGHUP, &act, NULL); sigaction(SIGHUP, &act, NULL);
#elif !WIN32 #elif !_WIN32
signal(SIGPIPE, plumber); signal(SIGPIPE, plumber);
signal(SIGHUP, hup); signal(SIGHUP, hup);
#endif #endif
@ -436,7 +437,7 @@ static void readConfiguration(void) {
goto lowMemory; goto lowMemory;
} }
srv->toPort = connectPort; srv->toPort = connectPort;
#ifndef WIN32 #ifndef _WIN32
if (fd > maxfd) { if (fd > maxfd) {
maxfd = fd; maxfd = fd;
} }
@ -699,7 +700,7 @@ static void handleClose(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
socket->fd = INVALID_SOCKET; socket->fd = INVALID_SOCKET;
if (other_socket->fd != INVALID_SOCKET) { if (other_socket->fd != INVALID_SOCKET) {
#ifndef __linux__ #ifndef __linux__
#ifndef WIN32 #ifndef _WIN32
/* Now set up the other end for a polite closing */ /* Now set up the other end for a polite closing */
/* Request a low-water mark equal to the entire /* Request a low-water mark equal to the entire
@ -708,7 +709,7 @@ static void handleClose(ConnectionInfo *cnx, Socket *socket, Socket *other_socke
int arg = 1024; int arg = 1024;
setsockopt(other_socket->fd, SOL_SOCKET, SO_SNDLOWAT, setsockopt(other_socket->fd, SOL_SOCKET, SO_SNDLOWAT,
&arg, sizeof(arg)); &arg, sizeof(arg));
#endif /* WIN32 */ #endif /* _WIN32 */
#endif /* __linux__ */ #endif /* __linux__ */
cnx->coLog = socket == &cnx->local ? cnx->coLog = socket == &cnx->local ?
logLocalClosedFirst : logRemoteClosedFirst; logLocalClosedFirst : logRemoteClosedFirst;
@ -739,7 +740,7 @@ static void handleAccept(ServerInfo const *srv)
int tmp = 1; int tmp = 1;
ioctlsocket(nfd, FIONBIO, &tmp); ioctlsocket(nfd, FIONBIO, &tmp);
#ifndef WIN32 #ifndef _WIN32
tmp = 0; tmp = 0;
setsockopt(nfd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp)); setsockopt(nfd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
#endif #endif
@ -843,7 +844,7 @@ static void handleAccept(ServerInfo const *srv)
memcpy(&saddr.sin_addr, &srv->localAddr, sizeof(struct in_addr)); memcpy(&saddr.sin_addr, &srv->localAddr, sizeof(struct in_addr));
saddr.sin_port = srv->localPort; saddr.sin_port = srv->localPort;
#ifndef WIN32 #ifndef _WIN32
#ifdef __linux__ #ifdef __linux__
tmp = 0; tmp = 0;
setsockopt(cnx->local.fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp)); setsockopt(cnx->local.fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));
@ -851,7 +852,7 @@ static void handleAccept(ServerInfo const *srv)
tmp = 1024; tmp = 1024;
setsockopt(cnx->local.fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)); setsockopt(cnx->local.fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp));
#endif /* __linux__ */ #endif /* __linux__ */
#endif /* WIN32 */ #endif /* _WIN32 */
tmp = 1; tmp = 1;
ioctlsocket(cnx->local.fd, FIONBIO, &tmp); ioctlsocket(cnx->local.fd, FIONBIO, &tmp);
@ -871,14 +872,14 @@ static void handleAccept(ServerInfo const *srv)
} }
} }
#ifndef WIN32 #ifndef _WIN32
if (cnx->local.fd > maxfd) { if (cnx->local.fd > maxfd) {
maxfd = cnx->local.fd; maxfd = cnx->local.fd;
} }
if (cnx->remote.fd > maxfd) { if (cnx->remote.fd > maxfd) {
maxfd = cnx->remote.fd; maxfd = cnx->remote.fd;
} }
#endif /* WIN32 */ #endif /* _WIN32 */
logEvent(cnx, srv, logOpened); logEvent(cnx, srv, logOpened);
} }
@ -942,7 +943,7 @@ static int getAddress(char const *host, struct in_addr *iaddr)
return -1; return -1;
} }
#if !HAVE_SIGACTION && !WIN32 #if !HAVE_SIGACTION && !_WIN32
RETSIGTYPE plumber(int s) RETSIGTYPE plumber(int s)
{ {
/* Just reinstall */ /* Just reinstall */
@ -950,7 +951,7 @@ RETSIGTYPE plumber(int s)
} }
#endif #endif
#if !WIN32 #if !_WIN32
RETSIGTYPE hup(int s) RETSIGTYPE hup(int s)
{ {
(void)s; (void)s;
@ -963,7 +964,7 @@ RETSIGTYPE hup(int s)
signal(SIGHUP, hup); signal(SIGHUP, hup);
#endif #endif
} }
#endif /* WIN32 */ #endif /* _WIN32 */
RETSIGTYPE quit(int s) RETSIGTYPE quit(int s)
{ {