From f3f3e961de10e6c1272099b40a4bbd74bb2e641f Mon Sep 17 00:00:00 2001 From: Guido Serassio Date: Sun, 31 May 2009 19:20:44 +0200 Subject: [PATCH] Windows port: first chunk of fixes needed to build again Squid3 using MinGW --- compat/os/mswin.h | 52 +++++---------------------- compat/osdetect.h | 5 ++- configure.in | 16 ++++++--- helpers/basic_auth/mswin_sspi/valid.c | 2 +- src/Makefile.am | 1 + src/acl/Arp.cc | 2 ++ src/dns_internal.cc | 9 +++-- src/main.cc | 4 +-- src/ufsdump.cc | 8 +++++ 9 files changed, 42 insertions(+), 57 deletions(-) diff --git a/compat/os/mswin.h b/compat/os/mswin.h index fd0860c9fa..17467f5bf2 100644 --- a/compat/os/mswin.h +++ b/compat/os/mswin.h @@ -49,6 +49,14 @@ #endif #endif +/* Some MinGW version defines min() and max() as macros + causing the fail of the build process. The following + #define will disable that definition + */ +#if defined(__GNUC__) +#define NOMINMAX +#endif + #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 # define __USE_FILE_OFFSET64 1 #endif @@ -720,49 +728,5 @@ struct rusage { #undef ACL - -/** \cond AUTODOCS-IGNORE */ -using namespace Squid; -/** \endcond */ - - -/* win32lib.c */ -SQUIDCEXTERN int chroot (const char *); -SQUIDCEXTERN int ftruncate(int, off_t); -#ifndef HAVE_GETTIMEOFDAY -SQUIDCEXTERN int gettimeofday(struct timeval * ,void *); -#endif -SQUIDCEXTERN int kill(pid_t, int); -SQUIDCEXTERN int statfs(const char *, struct statfs *); -SQUIDCEXTERN int truncate(const char *, off_t); -SQUIDCEXTERN const char * wsastrerror(int); -SQUIDCEXTERN struct passwd *getpwnam(char *); -SQUIDCEXTERN struct group *getgrnam(char *); -SQUIDCEXTERN uid_t geteuid(void); -SQUIDCEXTERN uid_t getuid(void); -SQUIDCEXTERN int setuid(uid_t); -SQUIDCEXTERN int seteuid(uid_t); -SQUIDCEXTERN gid_t getgid(void); -SQUIDCEXTERN gid_t getegid(void); -SQUIDCEXTERN int setgid(gid_t); -SQUIDCEXTERN int setegid(gid_t); -SQUIDCEXTERN const char *WIN32_strerror(int); -SQUIDCEXTERN void WIN32_maperror(unsigned long); - -// Moved in from squid.h and other duplicates. -// BUT was already included up the top there with a wrapped conditional. -// that may need checking.... -//#include - -/* Windows may lack getpagesize() prototype */ -// Moved in from squid.h -// NP: there may be a header include needed before this to prevent duplicate-definitions -// if that is true it will need including here as part of the hack. -// if not then this comment can be dropped. -#if !defined(getpagesize) -SQUIDCEXTERN size_t getpagesize(void); -#endif - - #endif /* _SQUID_WIN32_ */ #endif /* SQUID_OS_MSWIN_H */ diff --git a/compat/osdetect.h b/compat/osdetect.h index fb1eb9acad..bb8b1e1d0e 100644 --- a/compat/osdetect.h +++ b/compat/osdetect.h @@ -65,7 +65,10 @@ #define _SQUID_WIN32_ #elif defined(WIN32) || defined(WINNT) || defined(__WIN32__) || defined(__WIN32) -#define _SQUID_MSWIN_ +/* We are using _SQUID_MSWIN_ define in cf.data.pre, so + it must be defined to 1 to avoid the build failure of cfgen. + */ +#define _SQUID_MSWIN_ 1 #define _SQUID_WIN32_ #elif defined(__APPLE__) diff --git a/configure.in b/configure.in index 62e86a85a1..948c6f4bcb 100644 --- a/configure.in +++ b/configure.in @@ -3449,9 +3449,11 @@ main () WSAStartup(2, &wsaData); #endif if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) exit(1); - if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) exit(1); #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__)) + if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &len) < 0) exit(1); WSACleanup(); +#else + if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) exit(1); #endif if (val<=0) exit(1); fp = fopen("conftestval", "w"); @@ -3492,9 +3494,11 @@ main () WSAStartup(2, &wsaData); #endif if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) exit(1); - if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) exit(1); #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__)) + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &len) < 0) exit(1); WSACleanup(); +#else + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) exit(1); #endif if (val <= 0) exit(1); fp = fopen("conftestval", "w"); @@ -3535,9 +3539,11 @@ main () WSAStartup(2, &wsaData); #endif if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) exit(1); - if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) exit(1); #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__)) + if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &len) < 0) exit(1); WSACleanup(); +#else + if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) exit(1); #endif if (val <= 0) exit(1); fp = fopen("conftestval", "w"); @@ -3582,9 +3588,11 @@ main () WSAStartup(2, &wsaData); #endif if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) exit(1); - if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) exit(1); #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__)) + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &len) < 0) exit(1); WSACleanup(); +#else + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) exit(1); #endif if (val <= 0) exit(1); fp = fopen("conftestval", "w"); diff --git a/helpers/basic_auth/mswin_sspi/valid.c b/helpers/basic_auth/mswin_sspi/valid.c index ecb15c8311..42c1747f85 100644 --- a/helpers/basic_auth/mswin_sspi/valid.c +++ b/helpers/basic_auth/mswin_sspi/valid.c @@ -125,7 +125,7 @@ Valid_User(char *UserName, char *Password, char *Group) int result = NTV_SERVER_ERROR; size_t i; char NTDomain[256]; - char *domain_qualify; + char *domain_qualify = NULL; char DomainUser[256]; char User[256]; diff --git a/src/Makefile.am b/src/Makefile.am index 8c02760907..70d06f3e62 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -517,6 +517,7 @@ nodist_squid_SOURCES = \ squid_LDADD = \ $(COMMON_LIBS) \ icmp/libicmp.la icmp/libicmp-core.la \ + ../compat/libcompat.la \ -L../lib \ @XTRA_OBJS@ \ @DISK_LINKOBJS@ \ diff --git a/src/acl/Arp.cc b/src/acl/Arp.cc index 7d341a01e6..0108c9a76b 100644 --- a/src/acl/Arp.cc +++ b/src/acl/Arp.cc @@ -243,7 +243,9 @@ int aclMatchArp(SplayNode **dataptr, IpAddress &c) { struct arpreq arpReq; +#if !defined(_SQUID_WIN32_) struct sockaddr_in *sa = NULL; +#endif IpAddress ipAddr = c; diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 224de5c20c..15982731d3 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -480,15 +480,14 @@ idnsParseWIN32Registry(void) if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_TCPIP_PARA_INTERFACES, 0, KEY_READ, &hndKey) == ERROR_SUCCESS) { int i; - int MaxSubkeyLen; - DWORD InterfacesCount; + DWORD MaxSubkeyLen, InterfacesCount; char *keyname; FILETIME ftLastWriteTime; if (RegQueryInfoKey(hndKey, NULL, NULL, NULL, &InterfacesCount, &MaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { keyname = (char *) xmalloc(++MaxSubkeyLen); for (i = 0; i < (int) InterfacesCount; i++) { - int j; + DWORD j; j = MaxSubkeyLen; if (RegEnumKeyEx(hndKey, i, keyname, &j, NULL, NULL, NULL, &ftLastWriteTime) == ERROR_SUCCESS) { char *newkeyname; @@ -503,7 +502,7 @@ idnsParseWIN32Registry(void) Result = RegQueryValueEx(hndKey2, "DhcpNameServer", NULL, &Type, NULL, &Size); if (Result == ERROR_SUCCESS && Size) { t = (char *) xmalloc(Size); - RegQueryValueEx(hndKey2, "DhcpNameServer", NULL, &Type, t, &Size); + RegQueryValueEx(hndKey2, "DhcpNameServer", NULL, &Type, (LPBYTE)t, &Size); token = strtok(t, ", "); while (token) { debugs(78, 1, "Adding DHCP nameserver " << token << " from Registry"); @@ -516,7 +515,7 @@ idnsParseWIN32Registry(void) Result = RegQueryValueEx(hndKey2, "NameServer", NULL, &Type, NULL, &Size); if (Result == ERROR_SUCCESS && Size) { t = (char *) xmalloc(Size); - RegQueryValueEx(hndKey2, "NameServer", NULL, &Type, t, &Size); + RegQueryValueEx(hndKey2, "NameServer", NULL, &Type, (LPBYTE)t, &Size); token = strtok(t, ", "); while (token) { debugs(78, 1, "Adding nameserver " << token << " from Registry"); diff --git a/src/main.cc b/src/main.cc index f044b0be41..7aac0a18c7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1094,7 +1094,7 @@ mainInitialize(void) } /// unsafe main routine -- may throw -static int SquidMain(int argc, char **argv); +int SquidMain(int argc, char **argv); /// unsafe main routine wrapper to catch exceptions static int SquidMainSafe(int argc, char **argv); @@ -1125,7 +1125,7 @@ SquidMainSafe(int argc, char **argv) return -1; // not reached } -static int +int SquidMain(int argc, char **argv) { #ifdef _SQUID_WIN32_ diff --git a/src/ufsdump.cc b/src/ufsdump.cc index e65e93234d..9daf167934 100644 --- a/src/ufsdump.cc +++ b/src/ufsdump.cc @@ -82,6 +82,14 @@ CacheManager::GetInstance() void CacheManager::registerAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic) {} +/* MinGW needs also a stub of death() */ +void +death(int sig) +{ + std::cout << "Fatal: Signal " << sig; + exit (1); +} + /* end stub functions */ -- 2.47.2