From 2f4586ad044ba5deedadbccd4ad913c565ca3367 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 12 Oct 2013 16:11:14 +0300 Subject: [PATCH] Make the MinGW32 build compatible with MinGW runtime 4.x. nt/inc/dirent.h (struct dirent) [__MINGW_MAJOR_VERSION >= 4]: Make the layout of 'struct dirent' be compatible with MinGW32 runtime versions 4.0 and later. nt/inc/ms-w32.h (__MINGW_MAJOR_VERSION, __MINGW_MINOR_VERSION) (__MINGW_PATCHLEVEL) [!__MINGW64_VERSION_MAJOR]: Define, if not defined, but not for MinGW64. (_USE_32BIT_TIME_T) [__MINGW64_VERSION_MAJOR]: Define, to force use of 32-bit time_t type. --- nt/ChangeLog | 12 ++++++++++++ nt/inc/dirent.h | 21 +++++++++++++++++++++ nt/inc/ms-w32.h | 26 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/nt/ChangeLog b/nt/ChangeLog index 390a8eb0227..cdd9ec60b11 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog @@ -1,3 +1,15 @@ +2013-10-12 Eli Zaretskii + + * inc/dirent.h (struct dirent) [__MINGW_MAJOR_VERSION >= 4]: Make + the layout of 'struct dirent' be compatible with MinGW32 runtime + versions 4.0 and later. + + * inc/ms-w32.h (__MINGW_MAJOR_VERSION, __MINGW_MINOR_VERSION) + (__MINGW_PATCHLEVEL) [!__MINGW64_VERSION_MAJOR]: Define, if not + defined, but not for MinGW64. + (_USE_32BIT_TIME_T) [__MINGW64_VERSION_MAJOR]: Define, to force + use of 32-bit time_t type. + 2013-10-07 Paul Eggert Improve support for popcount and counting trailing zeros (Bug#15550). diff --git a/nt/inc/dirent.h b/nt/inc/dirent.h index 676b82d207b..328635c4853 100644 --- a/nt/inc/dirent.h +++ b/nt/inc/dirent.h @@ -19,6 +19,27 @@ struct dirent /* data from readdir() */ long d_ino; /* inode number of entry */ unsigned short d_reclen; /* length of this record */ unsigned short d_namlen; /* length of string in d_name */ +#if __MINGW_MAJOR_VERSION >= 4 + /* MinGW.org runtime 4.x introduces a modified layout of + 'struct dirent', which makes it binary incompatible with + previous versions. To add insult to injury, the MinGW + startup code calls 'readdir', which is implemented in + w32.c. So we need to define the same layout of this struct + as the MinGW runtime does, or else command-line globbing + will be broken. (Versions of MinGW runtime after 4.0 are + supposed not to call 'readdir' from startup code, but we + had better be safe than sorry.) */ + unsigned d_type; /* File attributes */ + /* The next 3 fields are declared 'time_t' in the MinGW 4.0 + headers, but 'time_t' is by default a 64-bit type in 4.x, + and presumably the libmingwex library was compiled using + that default definition. So we must use 64-bit types here, + even though our time_t is a 32-bit type. What a mess! */ + __int64 d_time_create; + __int64 d_time_access; /* always midnight local time */ + __int64 d_time_write; + _fsize_t d_size; +#endif char d_name[MAXNAMLEN+1]; /* name of file */ }; diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h index e670079eb35..d5257d9a937 100644 --- a/nt/inc/ms-w32.h +++ b/nt/inc/ms-w32.h @@ -24,6 +24,32 @@ along with GNU Emacs. If not, see . */ #define WINDOWSNT #endif +/* The @#$%^&! MinGW developers stopped updating the values of + __MINGW32_VERSION, __MINGW32_MAJOR_VERSION, and + __MINGW32_MINOR_VERSION values in v4.x of the runtime, to + "discourage its uses". So the values of those macros can no longer + be trusted, and we need the workaround below, to have a single set + of macros we can trust. (The .17 minor version is arbitrary.) */ +#ifdef __MINGW32__ +#include <_mingw.h> +#endif +/* MinGW64 doesn't have this problem, and does not define + __MINGW_VERSION. */ +#ifndef __MINGW64_VERSION_MAJOR +# ifndef __MINGW_VERSION +# define __MINGW_VERSION 3.17 +# undef __MINGW_MAJOR_VERSION +# define __MINGW_MAJOR_VERSION 3 +# undef __MINGW_MINOR_VERSION +# define __MINGW_MINOR_VERSION 17 +# undef __MINGW_PATCHLEVEL +# define __MINGW_PATCHLEVEL 0 +# endif +#endif +#if __MINGW_MAJOR_VERSION >= 4 +# define _USE_32BIT_TIME_T +#endif + /* #undef const */ /* Number of chars of output in the buffer of a stdio stream. */ -- 2.11.4.GIT