* [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps
@ 2020-05-19 6:24 Steve Lhomme
2020-05-28 6:24 ` Steve Lhomme
2020-05-29 0:04 ` Bruno Haible
0 siblings, 2 replies; 7+ messages in thread
From: Steve Lhomme @ 2020-05-19 6:24 UTC (permalink / raw)
To: bug-gnulib; +Cc: Steve Lhomme
LoadLibrary is forbidden in such apps (can only load DLLs from within the app
package).
The API entries are available to all apps linking with the Windows API as found
here:
https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis
windowsapp.lib (and mincore.lib for Windows 8) are both available in MinGW as
well.
GetSystemTimePreciseAsFileTime is only allowed in Win10 UWP apps.
---
lib/gettimeofday.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index 19804793a..087f7eada 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -45,12 +45,17 @@ static BOOL initialized = FALSE;
static void
initialize (void)
{
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */
+ /* LoadLibrary not allowed but the functions are available with the windows runtime */
+ GetSystemTimePreciseAsFileTimeFunc = GetSystemTimePreciseAsFileTime;
+#else /* WINAPI_PARTITION_DESKTOP */
HMODULE kernel32 = LoadLibrary ("kernel32.dll");
if (kernel32 != NULL)
{
GetSystemTimePreciseAsFileTimeFunc =
(GetSystemTimePreciseAsFileTimeFuncType) GetProcAddress (kernel32, "GetSystemTimePreciseAsFileTime");
}
+#endif /* WINAPI_PARTITION_DESKTOP */
initialized = TRUE;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps
2020-05-19 6:24 [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
@ 2020-05-28 6:24 ` Steve Lhomme
2020-05-29 0:04 ` Bruno Haible
1 sibling, 0 replies; 7+ messages in thread
From: Steve Lhomme @ 2020-05-28 6:24 UTC (permalink / raw)
To: bug-gnulib
Any update on this patch ?
On Dekstop it's better to use kernel32.dll as it's loaded with every
process, so the LoadLibrary is not loading any new DLL.
On Winstore/UWP apps you cannot use LoadLibrary, only LoadLibraryFromApp
which cannot be used to load system DLLs. Static linking in necessary in
this case. Any app targeting UWP is already using the windowsapp.lib
(replacing the kernel32 lib they used to link with) so no need to fore
linking with it via pkg-config, libtool, etc.
For example in CLang you either link with windowsapp or kernel32:
https://github.com/llvm-project/clang/blob/master/lib/Driver/ToolChains/MinGW.cpp#L269
On 2020-05-19 8:24, Steve Lhomme wrote:
> LoadLibrary is forbidden in such apps (can only load DLLs from within the app
> package).
> The API entries are available to all apps linking with the Windows API as found
> here:
> https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis
>
> windowsapp.lib (and mincore.lib for Windows 8) are both available in MinGW as
> well.
>
> GetSystemTimePreciseAsFileTime is only allowed in Win10 UWP apps.
> ---
> lib/gettimeofday.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
> index 19804793a..087f7eada 100644
> --- a/lib/gettimeofday.c
> +++ b/lib/gettimeofday.c
> @@ -45,12 +45,17 @@ static BOOL initialized = FALSE;
> static void
> initialize (void)
> {
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */
> + /* LoadLibrary not allowed but the functions are available with the windows runtime */
> + GetSystemTimePreciseAsFileTimeFunc = GetSystemTimePreciseAsFileTime;
> +#else /* WINAPI_PARTITION_DESKTOP */
> HMODULE kernel32 = LoadLibrary ("kernel32.dll");
> if (kernel32 != NULL)
> {
> GetSystemTimePreciseAsFileTimeFunc =
> (GetSystemTimePreciseAsFileTimeFuncType) GetProcAddress (kernel32, "GetSystemTimePreciseAsFileTime");
> }
> +#endif /* WINAPI_PARTITION_DESKTOP */
> initialized = TRUE;
> }
>
> --
> 2.26.2
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps
2020-05-19 6:24 [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
2020-05-28 6:24 ` Steve Lhomme
@ 2020-05-29 0:04 ` Bruno Haible
2020-05-29 5:12 ` Daiki Ueno
` (2 more replies)
1 sibling, 3 replies; 7+ messages in thread
From: Bruno Haible @ 2020-05-29 0:04 UTC (permalink / raw)
To: bug-gnulib; +Cc: Steve Lhomme
Hi,
Steve Lhomme wrote:
> LoadLibrary is forbidden in such apps (can only load DLLs from within the app
> package).
> The API entries are available to all apps linking with the Windows API as found
> here:
> https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis
Thanks for these infos.
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */
The GetSystemTimePreciseAsFileTime function is available starting with Windows 8,
therefore
- the condition with WINAPI_FAMILY_PARTITION is not necessary,
- the condition _WIN32_WINNT >= 0x0A00 is overly restrictive;
_WIN32_WINNT >= _WIN32_WINNT_WIN8 will work just as well.
I have added a page about the native Windows APIs at
https://gitlab.com/ghwiki/gnow-how/-/wikis/Platforms/Native_Windows
Then here is a patch to avoid LoadLibrary when possible.
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.
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index 1980479..3d53115 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -33,9 +33,11 @@
#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 (¤t_time);
else
diff --git a/lib/isatty.c b/lib/isatty.c
index 6cdc0fb..fc771d1 100644
--- a/lib/isatty.c
+++ b/lib/isatty.c
@@ -39,9 +39,11 @@
# 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>
diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index b9163f5..02ad9ab 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -40,18 +40,20 @@
#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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps
2020-05-29 0:04 ` Bruno Haible
@ 2020-05-29 5:12 ` Daiki Ueno
2020-05-29 10:34 ` Bruno Haible
2020-05-29 10:49 ` Steve Lhomme
2020-05-29 20:29 ` do not use GetModuleHandle " Bruno Haible
2 siblings, 1 reply; 7+ messages in thread
From: Daiki Ueno @ 2020-05-29 5:12 UTC (permalink / raw)
To: Bruno Haible; +Cc: Steve Lhomme, bug-gnulib
Hello,
Bruno Haible <bruno@clisp.org> writes:
> diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> index b9163f5..02ad9ab 100644
> --- a/lib/stat-w32.c
> +++ b/lib/stat-w32.c
> @@ -40,18 +40,20 @@
> #include "pathmax.h"
> #include "verify.h"
>
> +#if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
> +
I am totally unfamiliar with Windows code, but this change seems to
break MinGW cross build, because GetFinalPathNameByHandleFunc is defined
only if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA), but referred to from
_gl_convert_FILETIME_to_timespec without the guard:
../../gl/stat-w32.c: In function '_gl_fstat_by_handle':
../../gl/stat-w32.c:259:23: error: 'GetFinalPathNameByHandleFunc' undeclared (first use in this function); did you mean 'GetFinalPathNameByHandleW'?
259 | || (GetFinalPathNameByHandleFunc != NULL
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| GetFinalPathNameByHandleW
Regards,
--
Daiki Ueno
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps
2020-05-29 5:12 ` Daiki Ueno
@ 2020-05-29 10:34 ` Bruno Haible
0 siblings, 0 replies; 7+ messages in thread
From: Bruno Haible @ 2020-05-29 10:34 UTC (permalink / raw)
To: Daiki Ueno; +Cc: Steve Lhomme, bug-gnulib
Daiki Ueno wrote:
> this change seems to
> break MinGW cross build, because GetFinalPathNameByHandleFunc is defined
> only if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA), but referred to from
> _gl_convert_FILETIME_to_timespec without the guard:
Oops, indeed. With the appropriate _WIN32_WINNT setting, I'm getting errors in
all three files:
C:\cygwin64\home\bruno\testdir2\gllib\gettimeofday.c(95): error C2065: 'GetSystemTimePreciseAsFileTimeFunc': undeclared identifier
C:\cygwin64\home\bruno\testdir2\gllib\isatty.c(99): error C2065: 'GetNamedPipeClientProcessIdFunc': undeclared identifier
C:\cygwin64\home\bruno\testdir2\gllib\isatty.c(100): error C2065: 'QueryFullProcessImageNameFunc': undeclared identifier
C:\cygwin64\home\bruno\testdir2\gllib\stat-w32.c(259): error C2065: 'GetFinalPathNameByHandleFunc': undeclared identifier
This patch fixes it.
2020-05-29 Bruno Haible <bruno@clisp.org>
Fix compilation error on native Windows (regression from 2020-05-28).
Reported by Daiki Ueno.
* lib/gettimeofday.c (GetSystemTimePreciseAsFileTimeFunc): Define as
macro when not using dynamic loading.
* lib/isatty.c (GetNamedPipeClientProcessIdFunc,
QueryFullProcessImageNameFunc): Likewise.
* lib/stat-w32.c (GetFileInformationByHandleExFunc,
GetFinalPathNameByHandleFunc): Likewise.
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index 3d53115..93914ba 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -56,6 +56,10 @@ initialize (void)
initialized = TRUE;
}
+# else
+
+# define GetSystemTimePreciseAsFileTimeFunc GetSystemTimePreciseAsFileTime
+
# endif
#endif
diff --git a/lib/isatty.c b/lib/isatty.c
index fc771d1..4c5b8e3 100644
--- a/lib/isatty.c
+++ b/lib/isatty.c
@@ -71,6 +71,11 @@ initialize (void)
initialized = TRUE;
}
+#else
+
+# define GetNamedPipeClientProcessIdFunc GetNamedPipeClientProcessId
+# define QueryFullProcessImageNameFunc QueryFullProcessImageName
+
#endif
static BOOL IsConsoleHandle (HANDLE h)
diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index 02ad9ab..cca12dd 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -78,6 +78,11 @@ initialize (void)
initialized = TRUE;
}
+#else
+
+# define GetFileInformationByHandleExFunc GetFileInformationByHandleEx
+# define GetFinalPathNameByHandleFunc GetFinalPathNameByHandle
+
#endif
/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps
2020-05-29 0:04 ` Bruno Haible
2020-05-29 5:12 ` Daiki Ueno
@ 2020-05-29 10:49 ` Steve Lhomme
2020-05-29 20:29 ` do not use GetModuleHandle " Bruno Haible
2 siblings, 0 replies; 7+ messages in thread
From: Steve Lhomme @ 2020-05-29 10:49 UTC (permalink / raw)
To: bug-gnulib
On 2020-05-29 2:04, Bruno Haible wrote:
> Hi,
>
> Steve Lhomme wrote:
>> LoadLibrary is forbidden in such apps (can only load DLLs from within the app
>> package).
>> The API entries are available to all apps linking with the Windows API as found
>> here:
>> https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis
>
> Thanks for these infos.
>
>> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */
>
> The GetSystemTimePreciseAsFileTime function is available starting with Windows 8,
> therefore
> - the condition with WINAPI_FAMILY_PARTITION is not necessary,
> - the condition _WIN32_WINNT >= 0x0A00 is overly restrictive;
> _WIN32_WINNT >= _WIN32_WINNT_WIN8 will work just as well.
OK. I thought GetSystemTimePreciseAsFileTime was not available in Win8
UWP apps. But it seems it was:
https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-81-api-sets
> I have added a page about the native Windows APIs at
> https://gitlab.com/ghwiki/gnow-how/-/wikis/Platforms/Native_Windows
>
> Then here is a patch to avoid LoadLibrary when possible.
>
>
> 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.
>
> diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
> index 1980479..3d53115 100644
> --- a/lib/gettimeofday.c
> +++ b/lib/gettimeofday.c
> @@ -33,9 +33,11 @@
>
> #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 (¤t_time);
> else
> diff --git a/lib/isatty.c b/lib/isatty.c
> index 6cdc0fb..fc771d1 100644
> --- a/lib/isatty.c
> +++ b/lib/isatty.c
> @@ -39,9 +39,11 @@
> # 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>
> diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> index b9163f5..02ad9ab 100644
> --- a/lib/stat-w32.c
> +++ b/lib/stat-w32.c
> @@ -40,18 +40,20 @@
> #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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* do not use GetModuleHandle when built for Windows Store apps
2020-05-29 0:04 ` Bruno Haible
2020-05-29 5:12 ` Daiki Ueno
2020-05-29 10:49 ` Steve Lhomme
@ 2020-05-29 20:29 ` Bruno Haible
2 siblings, 0 replies; 7+ messages in thread
From: Bruno Haible @ 2020-05-29 20:29 UTC (permalink / raw)
To: bug-gnulib; +Cc: Steve Lhomme
GetModuleHandle is like LoadLibrary: it is used for dynamic lookup of
Windows API functions. And Windows Store apps can't use it.
This patch fixes some of the issues. The other ones, in poll.c and select.c,
are harder to fix, because it's not easy to link directly against ntdll.dll [1].
[1] https://stackoverflow.com/questions/35509388/link-to-ntdll-lib-and-call-functions-inside-ntdll-dll
2020-05-29 Bruno Haible <bruno@clisp.org>
Avoid dynamic lookup of Windows API functions when possible.
* lib/getaddrinfo.c (GetProcAddress, getaddrinfo_func,
freeaddrinfo_func, getnameinfo_func, getaddrinfo_ptr, freeaddrinfo_ptr,
getnameinfo_ptr): Don't define in a build for Windows XP or higher.
(use_win32_p): Define differently.
* lib/link.c (GetProcAddress, CreateHardLinkFuncType,
CreateHardLinkFunc, initialized, initialize): Don't define in a build
for Windows XP or higher.
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index 99cb709..1db9be8 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -86,9 +86,11 @@ freeaddrinfo (struct addrinfo *ai)
# ifdef WINDOWS_NATIVE
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
+
/* Avoid warnings from gcc -Wcast-function-type. */
-# define GetProcAddress \
- (void *) GetProcAddress
+# define GetProcAddress \
+ (void *) GetProcAddress
typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
const struct addrinfo*,
@@ -135,6 +137,29 @@ use_win32_p (void)
return 1;
}
+
+# else
+
+static int
+use_win32_p (void)
+{
+ static int done = 0;
+
+ if (!done)
+ {
+ done = 1;
+
+ gl_sockets_startup (SOCKETS_1_1);
+ }
+
+ return 1;
+}
+
+# define getaddrinfo_ptr getaddrinfo
+# define freeaddrinfo_ptr freeaddrinfo
+# define getnameinfo_ptr getnameinfo
+
+# endif
# endif
static bool
@@ -161,6 +186,7 @@ getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res)
+#undef getaddrinfo
{
struct addrinfo *tmp;
int port = 0;
@@ -362,6 +388,7 @@ getaddrinfo (const char *restrict nodename,
/* Free 'addrinfo' structure AI including associated storage. */
void
freeaddrinfo (struct addrinfo *ai)
+#undef freeaddrinfo
{
# ifdef WINDOWS_NATIVE
if (use_win32_p ())
@@ -388,6 +415,7 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
char *restrict node, socklen_t nodelen,
char *restrict service, socklen_t servicelen,
int flags)
+#undef getnameinfo
{
# ifdef WINDOWS_NATIVE
if (use_win32_p ())
diff --git a/lib/link.c b/lib/link.c
index 8e079d2..8680e3e 100644
--- a/lib/link.c
+++ b/lib/link.c
@@ -30,9 +30,11 @@
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
+
/* Avoid warnings from gcc -Wcast-function-type. */
-# define GetProcAddress \
- (void *) GetProcAddress
+# define GetProcAddress \
+ (void *) GetProcAddress
/* CreateHardLink was introduced only in Windows 2000. */
typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCSTR lpFileName,
@@ -53,14 +55,24 @@ initialize (void)
initialized = TRUE;
}
+# else
+
+# define CreateHardLinkFunc CreateHardLink
+
+# endif
+
int
link (const char *file1, const char *file2)
{
char *dir;
size_t len1 = strlen (file1);
size_t len2 = strlen (file2);
+
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
if (!initialized)
initialize ();
+# endif
+
if (CreateHardLinkFunc == NULL)
{
/* System does not support hard links. */
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-05-29 20:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 6:24 [PATCH] gettimeofday: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
2020-05-28 6:24 ` Steve Lhomme
2020-05-29 0:04 ` Bruno Haible
2020-05-29 5:12 ` Daiki Ueno
2020-05-29 10:34 ` Bruno Haible
2020-05-29 10:49 ` Steve Lhomme
2020-05-29 20:29 ` do not use GetModuleHandle " Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).