]> Savannah Git Hosting - gnulib.git/commitdiff
Avoid dynamic loading of Windows API functions when possible.
authorBruno Haible <bruno@clisp.org>
Fri, 29 May 2020 00:03:12 +0000 (02:03 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 29 May 2020 00:03:12 +0000 (02:03 +0200)
Reported by Steve Lhomme <robux4@ycbcr.xyz> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00182.html>.

* lib/gettimeofday.c (GetProcAddress,
GetSystemTimePreciseAsFileTimeFuncType,
GetSystemTimePreciseAsFileTimeFunc, initialized, initialize): Don't
define in a build for Windows 8 or higher.
* lib/isatty.c (GetProcAddress, GetNamedPipeClientProcessIdFuncType,
GetNamedPipeClientProcessIdFunc, QueryFullProcessImageNameFuncType,
QueryFullProcessImageNameFunc, initialized, initialize): Don't define
in a build for Windows Vista or higher.
* lib/stat-w32.c (GetProcAddress, GetFileInformationByHandleExFuncType,
GetFileInformationByHandleExFunc, GetFinalPathNameByHandleFuncType,
GetFinalPathNameByHandleFunc, initialized, initialize): Likewise.

ChangeLog
lib/gettimeofday.c
lib/isatty.c
lib/stat-w32.c

index 0a62f572db26ff99b187520aa812ddce2b17ea9c..c39bfd37234a76afea8eb808a06aa0498aa1ccaf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2020-05-28  Bruno Haible  <bruno@clisp.org>
+
+       Avoid dynamic loading of Windows API functions when possible.
+       Reported by Steve Lhomme <robux4@ycbcr.xyz> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00182.html>.
+       * lib/gettimeofday.c (GetProcAddress,
+       GetSystemTimePreciseAsFileTimeFuncType,
+       GetSystemTimePreciseAsFileTimeFunc, initialized, initialize): Don't
+       define in a build for Windows 8 or higher.
+       * lib/isatty.c (GetProcAddress, GetNamedPipeClientProcessIdFuncType,
+       GetNamedPipeClientProcessIdFunc, QueryFullProcessImageNameFuncType,
+       QueryFullProcessImageNameFunc, initialized, initialize): Don't define
+       in a build for Windows Vista or higher.
+       * lib/stat-w32.c (GetProcAddress, GetFileInformationByHandleExFuncType,
+       GetFileInformationByHandleExFunc, GetFinalPathNameByHandleFuncType,
+       GetFinalPathNameByHandleFunc, initialized, initialize): Likewise.
+
 2020-05-28  Paul Eggert  <eggert@cs.ucla.edu>
 
        explicit_bzero-tests: improve -Wmissing-declarations pacification
index 19804793a99783ebb04a45a83f6a7b5b5fb1c98f..3d53115d9f0bcedc3a533497c32d952cde8e2b1d 100644 (file)
 
 #ifdef WINDOWS_NATIVE
 
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
+
 /* Avoid warnings from gcc -Wcast-function-type.  */
-# define GetProcAddress \
-   (void *) GetProcAddress
+#  define GetProcAddress \
+    (void *) GetProcAddress
 
 /* GetSystemTimePreciseAsFileTime was introduced only in Windows 8.  */
 typedef void (WINAPI * GetSystemTimePreciseAsFileTimeFuncType) (FILETIME *lpTime);
@@ -54,6 +56,8 @@ initialize (void)
   initialized = TRUE;
 }
 
+# endif
+
 #endif
 
 /* This is a wrapper for gettimeofday.  It is used only on systems
@@ -84,8 +88,10 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
      <http://www.windowstimestamp.com/description>.  */
   FILETIME current_time;
 
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
   if (!initialized)
     initialize ();
+# endif
   if (GetSystemTimePreciseAsFileTimeFunc != NULL)
     GetSystemTimePreciseAsFileTimeFunc (&current_time);
   else
index 6cdc0fb14676c5cad1063dcf57c102bb6487b917..fc771d1036659b5aed3cf6733867384536ecb508 100644 (file)
 # include <io.h>
 #endif
 
+#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
+
 /* Avoid warnings from gcc -Wcast-function-type.  */
-#define GetProcAddress \
-  (void *) GetProcAddress
+# define GetProcAddress \
+   (void *) GetProcAddress
 
 /* GetNamedPipeClientProcessId was introduced only in Windows Vista.  */
 typedef BOOL (WINAPI * GetNamedPipeClientProcessIdFuncType) (HANDLE hPipe,
@@ -69,6 +71,8 @@ initialize (void)
   initialized = TRUE;
 }
 
+#endif
+
 static BOOL IsConsoleHandle (HANDLE h)
 {
   DWORD mode;
@@ -84,8 +88,10 @@ static BOOL IsCygwinConsoleHandle (HANDLE h)
   BOOL result = FALSE;
   ULONG processId;
 
+#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
   if (!initialized)
     initialize ();
+#endif
 
   /* GetNamedPipeClientProcessId
      <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getnamedpipeclientprocessid>
index b9163f56e230688417ee62c6a1263e40f01ea050..02ad9abe63f0672485366c175a9cc0cadb1d7b21 100644 (file)
 #include "pathmax.h"
 #include "verify.h"
 
+#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
+
 /* Avoid warnings from gcc -Wcast-function-type.  */
-#define GetProcAddress \
-  (void *) GetProcAddress
+# define GetProcAddress \
+   (void *) GetProcAddress
 
-#if _GL_WINDOWS_STAT_INODES == 2
+# if _GL_WINDOWS_STAT_INODES == 2
 /* GetFileInformationByHandleEx was introduced only in Windows Vista.  */
 typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile,
                                                                FILE_INFO_BY_HANDLE_CLASS fiClass,
                                                                LPVOID lpBuffer,
                                                                DWORD dwBufferSize);
 static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL;
-#endif
+# endif
 /* GetFinalPathNameByHandle was introduced only in Windows Vista.  */
 typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
                                                            LPSTR lpFilePath,
@@ -66,16 +68,18 @@ initialize (void)
   HMODULE kernel32 = LoadLibrary ("kernel32.dll");
   if (kernel32 != NULL)
     {
-#if _GL_WINDOWS_STAT_INODES == 2
+# if _GL_WINDOWS_STAT_INODES == 2
       GetFileInformationByHandleExFunc =
         (GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx");
-#endif
+# endif
       GetFinalPathNameByHandleFunc =
         (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
     }
   initialized = TRUE;
 }
 
+#endif
+
 /* Converts a FILETIME to GMT time since 1970-01-01 00:00:00.  */
 #if _GL_WINDOWS_STAT_TIMESPEC
 struct timespec
@@ -134,8 +138,10 @@ _gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
   DWORD type = GetFileType (h);
   if (type == FILE_TYPE_DISK)
     {
+#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
       if (!initialized)
         initialize ();
+#endif
 
       /* st_mode can be determined through
          GetFileAttributesEx