From: Amos Jeffries Date: Tue, 27 Jun 2023 16:50:16 +0000 (+0000) Subject: MinGW-w64: update libcompat structure (#1341) X-Git-Tag: SQUID_7_0_1~417 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49cd4f7c53f2308fd0e68687f44fad196c4eba8c;p=thirdparty%2Fsquid.git MinGW-w64: update libcompat structure (#1341) Separate the Squid for Windows portability fixes for MinGW and MSVC builds. Beginning a new MinGW-w64 specific port with a clean starting base. With these changes the libcompat portability library builds. The rest of Squid remains mostly non-building. --- diff --git a/compat/Makefile.am b/compat/Makefile.am index 88541c502e..17945a22d5 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -50,6 +50,7 @@ libcompatsquid_la_SOURCES = \ os/hpux.h \ os/linux.h \ os/macosx.h \ + os/mingw.h \ os/mswindows.h \ os/netbsd.h \ os/openbsd.h \ diff --git a/compat/compat.h b/compat/compat.h index b0c41433bf..6ca3e0a85c 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -68,6 +68,7 @@ #include "compat/os/hpux.h" #include "compat/os/linux.h" #include "compat/os/macosx.h" +#include "compat/os/mingw.h" #include "compat/os/mswindows.h" #include "compat/os/netbsd.h" #include "compat/os/openbsd.h" diff --git a/compat/mswindows.cc b/compat/mswindows.cc index 90ec3ffeb9..3922bbda23 100644 --- a/compat/mswindows.cc +++ b/compat/mswindows.cc @@ -12,7 +12,7 @@ #include "squid.h" // The following code section is part of an EXPERIMENTAL native Windows NT/2000 Squid port. -// Compiles only on MS Visual C++ or MinGW +// Compiles only on MS Visual C++ // CygWin appears not to need any of these #if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_ @@ -123,7 +123,6 @@ gettimeofday(struct timeval *pcur_time, void *tzp) } #endif /* !HAVE_GETTIMEOFDAY */ -#if !_SQUID_MINGW_ int WIN32_ftruncate(int fd, off_t size) { @@ -171,7 +170,6 @@ WIN32_truncate(const char *pathname, off_t length) return res; } -#endif /* !_SQUID_MINGW_ */ struct passwd * getpwnam(char *unused) { @@ -185,34 +183,6 @@ getgrnam(char *unused) { return &grp; } -#if _SQUID_MINGW_ -int -_free_osfhnd(int filehandle) -{ - if (((unsigned) filehandle < SQUID_MAXFD) && - (_osfile(filehandle) & FOPEN) && - (_osfhnd(filehandle) != (long) INVALID_HANDLE_VALUE)) { - switch (filehandle) { - case 0: - SetStdHandle(STD_INPUT_HANDLE, nullptr); - break; - case 1: - SetStdHandle(STD_OUTPUT_HANDLE, nullptr); - break; - case 2: - SetStdHandle(STD_ERROR_HANDLE, nullptr); - break; - } - _osfhnd(filehandle) = (long) INVALID_HANDLE_VALUE; - return (0); - } else { - errno = EBADF; /* bad handle */ - _doserrno = 0L; /* not an OS error */ - return -1; - } -} -#endif /* _SQUID_MINGW_ */ - struct errorentry { unsigned long WIN32_code; int POSIX_errno; diff --git a/compat/os/mingw.h b/compat/os/mingw.h new file mode 100644 index 0000000000..6abd702db8 --- /dev/null +++ b/compat/os/mingw.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 1996-2023 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#ifndef SQUID_OS_MINGW_H +#define SQUID_OS_MINGW_H + +#if _SQUID_MINGW_ + +/**************************************************************************** + *--------------------------------------------------------------------------* + * DO *NOT* MAKE ANY CHANGES below here unless you know what you're doing...* + *--------------------------------------------------------------------------* + ****************************************************************************/ + +// include this header before winsock2.h +#if HAVE_WS2TCPIP_H +#include +#endif + +// error: #warning Please include winsock2.h before windows.h +#if HAVE_WINSOCK2_H +#include +#endif + +// all windows native code requires windows.h +#if HAVE_WINDOWS_H +#include +#endif + +#endif /* _SQUID_MINGW_*/ +#endif /* SQUID_OS_MINGW_H */ diff --git a/compat/os/mswindows.h b/compat/os/mswindows.h index 3bf8796b20..73c5939bba 100644 --- a/compat/os/mswindows.h +++ b/compat/os/mswindows.h @@ -22,16 +22,6 @@ *--------------------------------------------------------------------------* ****************************************************************************/ -/* we target Windows XP and later - some API are missing otherwise */ -#if _SQUID_MINGW_ -#if WINVER < 0x0501 -#undef WINVER -#define WINVER 0x0501 -#undef _WIN32_WINNT -#define _WIN32_WINNT WINVER -#endif -#endif /* _SQUID_MINGW_ */ - #include "compat/initgroups.h" #if HAVE_DIRECT_H @@ -56,19 +46,6 @@ #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__) && !NOMINMAX -#define NOMINMAX -#endif - -/// some builds of MinGW do not define IPV6_V6ONLY socket option -#if !defined(IPV6_V6ONLY) -#define IPV6_V6ONLY 27 -#endif - #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 # define __USE_FILE_OFFSET64 1 #endif @@ -112,7 +89,7 @@ typedef unsigned long ino_t; #define vsnprintf _vsnprintf #endif -/* Microsoft C Compiler and CygWin need these. MinGW does not */ +/* Microsoft C Compiler and CygWin need these. */ #if defined(_MSC_VER) || _SQUID_CYGWIN_ SQUIDCEXTERN int WIN32_ftruncate(int fd, off_t size); #define ftruncate WIN32_ftruncate @@ -237,12 +214,6 @@ SQUIDCEXTERN int WIN32_truncate(const char *pathname, off_t length); #define SIGUSR1 30 /* user defined signal 1 */ #define SIGUSR2 31 /* user defined signal 2 */ -#if _SQUID_MINGW_ -typedef unsigned char boolean; -typedef unsigned char u_char; -typedef unsigned int u_int; -#endif - #if defined(_MSC_VER) typedef int uid_t; typedef int gid_t; @@ -422,11 +393,6 @@ SQUIDCEXTERN _CRTIMP ioinfo * __pioinfo[]; SQUIDCEXTERN int __cdecl _free_osfhnd(int); #endif -#if _SQUID_MINGW_ -__MINGW_IMPORT ioinfo * __pioinfo[]; -SQUIDCEXTERN int _free_osfhnd(int); -#endif - SQUIDCEXTERN THREADLOCAL int ws32_result; #if defined(__cplusplus) @@ -935,11 +901,6 @@ setgid (gid_t gid) return 0; } -/* for some reason autoconf misdetects getpagesize.. */ -#if HAVE_GETPAGESIZE && _SQUID_MINGW_ -#undef HAVE_GETPAGESIZE -#endif - #if !HAVE_GETPAGESIZE /* And now we define a compatibility layer */ size_t getpagesize(); @@ -992,24 +953,6 @@ void openlog(const char *ident, int logopt, int facility); void syslog(int priority, const char *fmt, ...); #endif -#if _SQUID_MINGW_ -/* MinGW missing bits from sys/wait.h */ -/* A status looks like: - * <2 bytes info> <2 bytes code> - * - * == 0, child has exited, info is the exit value - * == 1..7e, child has exited, info is the signal number. - * == 7f, child has stopped, info was the signal number. - * == 80, there was a core dump. - */ -#define WIFEXITED(w) (((w) & 0xff) == 0) -#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f)) -#define WIFSTOPPED(w) (((w) & 0xff) == 0x7f) -#define WEXITSTATUS(w) (((w) >> 8) & 0xff) -#define WTERMSIG(w) ((w) & 0x7f) -#define WSTOPSIG WEXITSTATUS -#endif - /* prototypes */ void WIN32_maperror(unsigned long WIN32_oserrno); diff --git a/compat/osdetect.h b/compat/osdetect.h index b1fa387fdb..8f40c2cfee 100644 --- a/compat/osdetect.h +++ b/compat/osdetect.h @@ -66,7 +66,6 @@ #elif defined(__MINGW32__) || defined(__MINGW__) #define _SQUID_MINGW_ 1 -#define _SQUID_WINDOWS_ 1 #elif defined(WIN32) || defined(WINNT) || defined(__WIN32__) || defined(__WIN32) #define _SQUID_WINDOWS_ 1 diff --git a/compat/statvfs.cc b/compat/statvfs.cc index 7928dbfe66..4df91b21a9 100644 --- a/compat/statvfs.cc +++ b/compat/statvfs.cc @@ -21,7 +21,7 @@ int xstatvfs(const char *path, struct statvfs *sfs) { -#if !HAVE_STATFS && _SQUID_WINDOWS_ +#if !HAVE_STATFS && (_SQUID_MINGW_ || _SQUID_WINDOWS_) char drive[4]; DWORD spc, bps, freec, totalc; DWORD vsn, maxlen, flags;