]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
Improve pattern for defining _WIN32_WINNT.
authorBruno Haible <bruno@clisp.org>
Thu, 28 May 2020 00:06:51 +0000 (02:06 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 28 May 2020 00:06:51 +0000 (02:06 +0200)
Newer versions of the Windows API may not only add, but also remove API
functions. Therefore, when the user is e.g. building for Windows 10, we
should not set _WIN32_WINNT to e.g. Windows 8, as this may enable the
use of APIs that were present in Windows 8 but removed in Windows 10.

Suggested by Steve Lhomme <robux4@ycbcr.xyz> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00318.html>.

* lib/ftruncate.c (_WIN32_WINNT): Don't set to a smaller value.
* lib/sethostname.c (_WIN32_WINNT): Likewise.
* lib/stat-w32.c (_WIN32_WINNT): Likewise.

ChangeLog
lib/ftruncate.c
lib/sethostname.c
lib/stat-w32.c

index aa0843944d4ae05351f41f3902253fe02d95f6af..ae76e2c9559ca822be462fd22559c744d72dee10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2020-05-27  Bruno Haible  <bruno@clisp.org>
+
+       Improve pattern for defining _WIN32_WINNT.
+       Newer versions of the Windows API may not only add, but also remove API
+       functions. Therefore, when the user is e.g. building for Windows 10, we
+       should not set _WIN32_WINNT to e.g. Windows 8, as this may enable the
+       use of APIs that were present in Windows 8 but removed in Windows 10.
+       Suggested by Steve Lhomme <robux4@ycbcr.xyz> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00318.html>.
+       * lib/ftruncate.c (_WIN32_WINNT): Don't set to a smaller value.
+       * lib/sethostname.c (_WIN32_WINNT): Likewise.
+       * lib/stat-w32.c (_WIN32_WINNT): Likewise.
+
 2020-05-27  Bruno Haible  <bruno@clisp.org>
 
        javacomp: Make more robust in multithreaded applications.
index a1856374e8f5a55002ee21cea644475efe24dac2..2514075e519623e77f433890b3d318e9b2c94ae9 100644 (file)
    argument.  So, define a 64-bit safe SetFileSize function ourselves.  */
 
 /* Ensure that <windows.h> declares GetFileSizeEx.  */
-#  undef _WIN32_WINNT
-#  define _WIN32_WINNT _WIN32_WINNT_WIN2K
+#  if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN2K)
+#   undef _WIN32_WINNT
+#   define _WIN32_WINNT _WIN32_WINNT_WIN2K
+#  endif
 
 /* Get declarations of the native Windows API functions.  */
 #  define WIN32_LEAN_AND_MEAN
index 1be69beabbcb56a2f194db3f257f3c5580f0402f..96318fb801f3d502002130c8ff3806f72b78c4be 100644 (file)
 /* Unix API.  */
 
 /* Specification.  */
-#include <unistd.h>
+# include <unistd.h>
 
-#include <errno.h>
-#include <stdio.h>
-#include <limits.h>
+# include <errno.h>
+# include <stdio.h>
+# include <limits.h>
 
 /* Set up to LEN chars of NAME as system hostname.
    Return 0 if ok, set errno and return -1 on error. */
@@ -43,7 +43,7 @@ sethostname (const char *name, size_t len)
       return -1;
     }
 
-#ifdef __minix /* Minix */
+# ifdef __minix /* Minix */
   {
     FILE *hostf;
     int r = 0;
@@ -76,38 +76,40 @@ sethostname (const char *name, size_t len)
 
     return r;
   }
-#else
+# else
   /* For platforms that we don't have a better option for, simply bail
      out.  */
   errno = ENOSYS;
   return -1;
-#endif
+# endif
 }
 
 #else
 /* Native Windows API.  Also used on Cygwin.  */
 
 /* Ensure that <windows.h> declares SetComputerNameEx.  */
-#undef _WIN32_WINNT
-#define _WIN32_WINNT _WIN32_WINNT_WIN2K
+# if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN2K)
+#  undef _WIN32_WINNT
+#  define _WIN32_WINNT _WIN32_WINNT_WIN2K
+# endif
 
-#define WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
 
 /* Specification.  */
-#include <unistd.h>
+# include <unistd.h>
 
-#include <errno.h>
-#include <limits.h>
-#include <string.h>
+# include <errno.h>
+# include <limits.h>
+# include <string.h>
 
-#include <windows.h>
+# include <windows.h>
 /* The mingw header files don't define GetComputerNameEx, SetComputerNameEx.  */
-#ifndef GetComputerNameEx
-# define GetComputerNameEx GetComputerNameExA
-#endif
-#ifndef SetComputerNameEx
-# define SetComputerNameEx SetComputerNameExA
-#endif
+# ifndef GetComputerNameEx
+#  define GetComputerNameEx GetComputerNameExA
+# endif
+# ifndef SetComputerNameEx
+#  define SetComputerNameEx SetComputerNameExA
+# endif
 
 /* Set up to LEN chars of NAME as system hostname.
    Return 0 if ok, set errno and return -1 on error. */
index 296ccf18cacec9a9c556322c91207c9591e18396..c4b5de9a7118a52cc46d20f5df5f7d316b4503b6 100644 (file)
 #if defined _WIN32 && ! defined __CYGWIN__
 
 /* Ensure that <windows.h> defines FILE_ID_INFO.  */
-#undef _WIN32_WINNT
-#define _WIN32_WINNT _WIN32_WINNT_WIN8
+#if !defined _WIN32_WINNT || (_WIN32_WINNT < _WIN32_WINNT_WIN8)
+# undef _WIN32_WINNT
+# define _WIN32_WINNT _WIN32_WINNT_WIN8
+#endif
 
 #include <sys/types.h>
 #include <sys/stat.h>