bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA
@ 2020-05-19  6:26 Steve Lhomme
  2020-05-19  6:26 ` [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
  2020-05-28  0:43 ` [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Bruno Haible
  0 siblings, 2 replies; 13+ messages in thread
From: Steve Lhomme @ 2020-05-19  6:26 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Steve Lhomme

The GetProcAddress uses the ANSI version of the API so the proper type for the
string is LPSTR, as found here:

https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea
---
 lib/stat-w32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index 296ccf18c..106d25120 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -52,7 +52,7 @@ static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = N
 #endif
 /* GetFinalPathNameByHandle was introduced only in Windows Vista.  */
 typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
-                                                           LPTSTR lpFilePath,
+                                                           LPSTR lpFilePath,
                                                            DWORD lenFilePath,
                                                            DWORD dwFlags);
 static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps
  2020-05-19  6:26 [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Steve Lhomme
@ 2020-05-19  6:26 ` Steve Lhomme
  2020-05-28  6:26   ` Steve Lhomme
  2020-05-30  9:21   ` Bruno Haible
  2020-05-28  0:43 ` [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Bruno Haible
  1 sibling, 2 replies; 13+ messages in thread
From: Steve Lhomme @ 2020-05-19  6:26 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.

GetFinalPathNameByHandleA is only allowed in Win10 UWP apps
GetFileInformationByHandleEx is allowed in Win8 and Win10 UWP apps.
---
 lib/stat-w32.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index 106d25120..6900dfcf5 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -61,6 +61,15 @@ static BOOL initialized = FALSE;
 static void
 initialize (void)
 {
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+  /* LoadLibrary not allowed but the functions are available with the windows runtime */
+#if _GL_WINDOWS_STAT_INODES == 2
+  GetFileInformationByHandleExFunc = GetFileInformationByHandleEx;
+#endif
+#if _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */
+  GetFinalPathNameByHandleFunc = GetFinalPathNameByHandleA;
+#endif
+#else /* WINAPI_PARTITION_DESKTOP */
   HMODULE kernel32 = LoadLibrary ("kernel32.dll");
   if (kernel32 != NULL)
     {
@@ -71,6 +80,7 @@ initialize (void)
       GetFinalPathNameByHandleFunc =
         (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
     }
+#endif /* WINAPI_PARTITION_DESKTOP */
   initialized = TRUE;
 }
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA
  2020-05-19  6:26 [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Steve Lhomme
  2020-05-19  6:26 ` [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
@ 2020-05-28  0:43 ` Bruno Haible
  2020-05-28  1:07   ` Jeffrey Walton
  2020-05-30  9:16   ` Don't assume that UNICODE is not defined Bruno Haible
  1 sibling, 2 replies; 13+ messages in thread
From: Bruno Haible @ 2020-05-28  0:43 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Steve Lhomme

Hi Steve,

> The GetProcAddress uses the ANSI version of the API so the proper type for the
> string is LPSTR, as found here:
> 
> https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea
> ---
>  lib/stat-w32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> index 296ccf18c..106d25120 100644
> --- a/lib/stat-w32.c
> +++ b/lib/stat-w32.c
> @@ -52,7 +52,7 @@ static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = N
>  #endif
>  /* GetFinalPathNameByHandle was introduced only in Windows Vista.  */
>  typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
> -                                                           LPTSTR lpFilePath,
> +                                                           LPSTR lpFilePath,
>                                                             DWORD lenFilePath,
>                                                             DWORD dwFlags);
>  static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;

The patch is good. Thanks. But there are more instances of the same problem.

When you present a suggestion or report a bug, please try to answer the main
questions:
  * What goes wrong?
  * Under which conditions does it go wrong?

In this case, when the application defines the macro UNICODE, the function types
are defined with wrong parameter types. That's because some types depend on
whether UNICODE is defined or not [1].

Once the problem has been stated like this, it's easy to find all occurrences
of the same problem: grep -rnw '\(TCHAR\|LPTSTR\|LPCTSTR\)' .

[1] https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types


2020-05-27  Bruno Haible  <bruno@clisp.org>

	Don't assume that UNICODE is not defined.
	Some Windows types, such as TCHAR, LPTSTR, LPCTSTR, are defined
	differently if the application defines the macro UNICODE.
	Reported by Steve Lhomme <robux4@ycbcr.xyz> in
	<https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00184.html>.
	* lib/link.c (CreateHardLinkFuncType): Use LPCSTR, not LPCTSTR.
	* lib/localename.c (enum_locales_fn): Use LPSTR, not LPTSTR.
	* lib/stat-w32.c (GetFinalPathNameByHandleFuncType): Likewise.

diff --git a/lib/link.c b/lib/link.c
index fc3eebf..8e079d2 100644
--- a/lib/link.c
+++ b/lib/link.c
@@ -35,8 +35,8 @@
     (void *) GetProcAddress
 
 /* CreateHardLink was introduced only in Windows 2000.  */
-typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCTSTR lpFileName,
-                                                LPCTSTR lpExistingFileName,
+typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCSTR lpFileName,
+                                                LPCSTR lpExistingFileName,
                                                 LPSECURITY_ATTRIBUTES lpSecurityAttributes);
 static CreateHardLinkFuncType CreateHardLinkFunc = NULL;
 static BOOL initialized = FALSE;
diff --git a/lib/localename.c b/lib/localename.c
index fe3d168..4046a0b 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -2564,7 +2564,7 @@ static char lname[LC_MAX * (LOCALE_NAME_MAX_LENGTH + 1) + 1];
 
 /* Callback function for EnumLocales.  */
 static BOOL CALLBACK
-enum_locales_fn (LPTSTR locale_num_str)
+enum_locales_fn (LPSTR locale_num_str)
 {
   char *endp;
   char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index c4b5de9..b9163f5 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -54,7 +54,7 @@ static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = N
 #endif
 /* GetFinalPathNameByHandle was introduced only in Windows Vista.  */
 typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
-                                                           LPTSTR lpFilePath,
+                                                           LPSTR lpFilePath,
                                                            DWORD lenFilePath,
                                                            DWORD dwFlags);
 static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA
  2020-05-28  0:43 ` [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Bruno Haible
@ 2020-05-28  1:07   ` Jeffrey Walton
  2020-05-30  9:16   ` Don't assume that UNICODE is not defined Bruno Haible
  1 sibling, 0 replies; 13+ messages in thread
From: Jeffrey Walton @ 2020-05-28  1:07 UTC (permalink / raw)
  To: Bruno Haible; +Cc: Steve Lhomme, bug-gnulib

On Wed, May 27, 2020 at 8:43 PM Bruno Haible <bruno@clisp.org> wrote:
>
> > The GetProcAddress uses the ANSI version of the API so the proper type for the
> > string is LPSTR, as found here:
> >
> > https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea
> > ---
> >  lib/stat-w32.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> > index 296ccf18c..106d25120 100644
> > --- a/lib/stat-w32.c
> > +++ b/lib/stat-w32.c
> > @@ -52,7 +52,7 @@ static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = N
> >  #endif
> >  /* GetFinalPathNameByHandle was introduced only in Windows Vista.  */
> >  typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
> > -                                                           LPTSTR lpFilePath,
> > +                                                           LPSTR lpFilePath,
> >                                                             DWORD lenFilePath,
> >                                                             DWORD dwFlags);
> >  static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
>
> The patch is good. Thanks. But there are more instances of the same problem.
>
> ...
>
> 2020-05-27  Bruno Haible  <bruno@clisp.org>
>
>         Don't assume that UNICODE is not defined.
>         Some Windows types, such as TCHAR, LPTSTR, LPCTSTR, are defined
>         differently if the application defines the macro UNICODE.
>         Reported by Steve Lhomme <robux4@ycbcr.xyz> in
>         <https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00184.html>.
>         * lib/link.c (CreateHardLinkFuncType): Use LPCSTR, not LPCTSTR.
>         * lib/localename.c (enum_locales_fn): Use LPSTR, not LPTSTR.
>         * lib/stat-w32.c (GetFinalPathNameByHandleFuncType): Likewise.
>
> diff --git a/lib/link.c b/lib/link.c
> index fc3eebf..8e079d2 100644
> --- a/lib/link.c
> +++ b/lib/link.c
> @@ -35,8 +35,8 @@
>      (void *) GetProcAddress
>
>  /* CreateHardLink was introduced only in Windows 2000.  */
> -typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCTSTR lpFileName,
> -                                                LPCTSTR lpExistingFileName,
> +typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCSTR lpFileName,
> +                                                LPCSTR lpExistingFileName,
>                                                  LPSECURITY_ATTRIBUTES lpSecurityAttributes);
>  static CreateHardLinkFuncType CreateHardLinkFunc = NULL;
>  static BOOL initialized = FALSE;
> diff --git a/lib/localename.c b/lib/localename.c
> index fe3d168..4046a0b 100644
> --- a/lib/localename.c
> +++ b/lib/localename.c
> @@ -2564,7 +2564,7 @@ static char lname[LC_MAX * (LOCALE_NAME_MAX_LENGTH + 1) + 1];
>
>  /* Callback function for EnumLocales.  */
>  static BOOL CALLBACK
> -enum_locales_fn (LPTSTR locale_num_str)
> +enum_locales_fn (LPSTR locale_num_str)
>  {
>    char *endp;
>    char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
> diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> index c4b5de9..b9163f5 100644
> --- a/lib/stat-w32.c
> +++ b/lib/stat-w32.c
> @@ -54,7 +54,7 @@ static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = N
>  #endif
>  /* GetFinalPathNameByHandle was introduced only in Windows Vista.  */
>  typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
> -                                                           LPTSTR lpFilePath,
> +                                                           LPSTR lpFilePath,
>                                                             DWORD lenFilePath,
>                                                             DWORD dwFlags);
>  static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
>

One small comment...

For Microsoft platforms, one should also include <tchar.h> when
available. The headers is common on many MS platforms, from Windows 95
through about Windows 8. I don't know if modern MS platforms have the
header since Microsoft has pushed to Unicode-only API.

Maybe an Autotools test would be the best course of action to guard the include.

Jeff


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps
  2020-05-19  6:26 ` [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
@ 2020-05-28  6:26   ` Steve Lhomme
  2020-05-30  9:21   ` Bruno Haible
  1 sibling, 0 replies; 13+ messages in thread
From: Steve Lhomme @ 2020-05-28  6:26 UTC (permalink / raw)
  To: bug-gnulib

Any update on this ?

Just as in gettimeofday, one cannot use LoadLibrary to load system DLLs 
in UWP builds. But they are available by static linking with windowsapp 
and are guaranteed to be there.

On 2020-05-19 8:26, 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.
> 
> GetFinalPathNameByHandleA is only allowed in Win10 UWP apps
> GetFileInformationByHandleEx is allowed in Win8 and Win10 UWP apps.
> ---
>   lib/stat-w32.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> index 106d25120..6900dfcf5 100644
> --- a/lib/stat-w32.c
> +++ b/lib/stat-w32.c
> @@ -61,6 +61,15 @@ static BOOL initialized = FALSE;
>   static void
>   initialize (void)
>   {
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> +  /* LoadLibrary not allowed but the functions are available with the windows runtime */
> +#if _GL_WINDOWS_STAT_INODES == 2
> +  GetFileInformationByHandleExFunc = GetFileInformationByHandleEx;
> +#endif
> +#if _WIN32_WINNT >= 0x0A00 /* _WIN32_WINNT_WIN10 */
> +  GetFinalPathNameByHandleFunc = GetFinalPathNameByHandleA;
> +#endif
> +#else /* WINAPI_PARTITION_DESKTOP */
>     HMODULE kernel32 = LoadLibrary ("kernel32.dll");
>     if (kernel32 != NULL)
>       {
> @@ -71,6 +80,7 @@ initialize (void)
>         GetFinalPathNameByHandleFunc =
>           (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
>       }
> +#endif /* WINAPI_PARTITION_DESKTOP */
>     initialized = TRUE;
>   }
>   
> -- 
> 2.26.2
> 
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Don't assume that UNICODE is not defined
  2020-05-28  0:43 ` [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Bruno Haible
  2020-05-28  1:07   ` Jeffrey Walton
@ 2020-05-30  9:16   ` Bruno Haible
  2020-05-30 10:57     ` Jeffrey Walton
  2020-05-30 12:46     ` Steve Lhomme
  1 sibling, 2 replies; 13+ messages in thread
From: Bruno Haible @ 2020-05-30  9:16 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Steve Lhomme

I wrote:
> some types depend on
> whether UNICODE is defined or not [1].

Some functions also depend whether UNICODE is defined or not.

Since UWP applications are meant to defined the macro UNICODE, but we want
Gnulib to produce the same code, regardless whether UNICODE is defined or not,
we need to either explicitly use the functions with 'A' suffix (which is ugly)
or use #defines for redirection.

Fortunately, packages that use gnulib don't need to do this stuff; nor do we
need to do it in the tests/ directory. Only the gnulib/lib/ directory may
reasonably be used with -DUNICODE, therefore only the gnulib/lib/ directory
needs this workaround.


2020-05-30  Bruno Haible  <bruno@clisp.org>

	Don't assume that UNICODE is not defined.
	Many Windows API functions are defined differently (redirecting to a
	function with suffix 'W') if the application defines the macro UNICODE
	than by default (redirecting to a function with suffix 'A').
	* lib/clean-temp.c (OSVERSIONINFO, GetVersionEx): Redirect to the
	variant with suffix 'A'.
	* lib/dirent-private.h (WIN32_FIND_DATA): Likewise.
	* lib/gc-gnulib.c (CryptAcquireContext): Likewise.
	* lib/getaddrinfo.c (GetModuleHandle): Likewise.
	* lib/getlogin.c (GetUserName): Likewise.
	* lib/getlogin_r.c (GetUserName): Likewise.
	* lib/gettimeofday.c (LoadLibrary): Likewise.
	* lib/isatty.c (LoadLibrary, QueryFullProcessImageName): Likewise.
	* lib/link.c (GetModuleHandle, CreateHardLink): Likewise.
	* lib/localename.c (GetLocaleInfo, EnumSystemLocales): Likewise.
	* lib/mountlist.c (GetDriveType): Likewise.
	* lib/nonblocking.c (GetNamedPipeHandleState): Likewise.
	* lib/opendir.c (WIN32_FIND_DATA, GetFullPathName, FindFirstFile):
	Likewise.
	* lib/physmem.c (GetModuleHandle): Likewise.
	* lib/poll.c (GetModuleHandle, PeekConsoleInput, CreateEvent,
	PeekMessage, DispatchMessage): Likewise.
	* lib/progreloc.c (GetModuleFileName): Likewise.
	* lib/putenv.c (SetEnvironmentVariable): Likewise.
	* lib/read.c (GetNamedPipeHandleState): Likewise.
	* lib/readdir.c (FindNextFile): Likewise.
	* lib/relocatable.c (GetModuleFileName): Likewise.
	* lib/rename.c (MoveFileEx): Likewise.
	* lib/rewinddir.c (FindFirstFile): Likewise.
	* lib/select.c (GetModuleHandle, PeekConsoleInput, CreateEvent,
	PeekMessage, DispatchMessage): Likewise.
	* lib/sethostname.c (GetComputerNameEx, SetComputerNameEx): Likewise.
	* lib/socket.c (WSASocket): Likewise.
	* lib/stat-w32.c (LoadLibrary, GetFinalPathNameByHandle): Likewise.
	* lib/stat.c (WIN32_FIND_DATA, CreateFile, FindFirstFile): Likewise.
	* lib/stdio-read.c (GetNamedPipeHandleState): Likewise.
	* lib/stdio-write.c (GetNamedPipeHandleState): Likewise.
	* lib/tmpdir.c (GetTempPath): Likewise.
	* lib/tmpfile.c (OSVERSIONINFO, GetVersionEx, GetTempPath): Likewise.
	* lib/uname.c (OSVERSIONINFO, GetVersionEx): Likewise.
	* lib/utime.c (CreateFile, GetFileAttributes): Likewise.
	* lib/windows-cond.c (CreateEvent): Likewise.
	* lib/windows-rwlock.c (CreateEvent): Likewise.
	* lib/windows-timedmutex.c (CreateEvent): Likewise.
	* lib/windows-timedrecmutex.c (CreateEvent): Likewise.
	* lib/windows-timedrwlock.c (CreateEvent): Likewise.
	* lib/write.c (GetNamedPipeHandleState): Likewise.

diff --git a/lib/clean-temp.c b/lib/clean-temp.c
index 8d3cbd9..c57d658 100644
--- a/lib/clean-temp.c
+++ b/lib/clean-temp.c
@@ -66,6 +66,14 @@
 # define PATH_MAX 1024
 #endif
 
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef OSVERSIONINFO
+# define OSVERSIONINFO OSVERSIONINFOA
+# undef GetVersionEx
+# define GetVersionEx GetVersionExA
+#endif
+
 
 /* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
    ensure that while constructing or modifying the data structures, the field
diff --git a/lib/dirent-private.h b/lib/dirent-private.h
index 4b4eba4..a3c6844 100644
--- a/lib/dirent-private.h
+++ b/lib/dirent-private.h
@@ -20,6 +20,10 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#undef WIN32_FIND_DATA
+#define WIN32_FIND_DATA WIN32_FIND_DATAA
+
 struct gl_directory
 {
   /* Status, or error code to produce in next readdir() call.
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index 8e9b88f..84f42e4 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -89,6 +89,12 @@ HCRYPTPROV g_hProv = 0;
 # endif
 #endif
 
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef CryptAcquireContext
+# define CryptAcquireContext CryptAcquireContextA
+#endif
+
 Gc_rc
 gc_init (void)
 {
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index 1db9be8..8d2c01c 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -86,6 +86,10 @@ freeaddrinfo (struct addrinfo *ai)
 
 # ifdef WINDOWS_NATIVE
 
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetModuleHandle
+#  define GetModuleHandle GetModuleHandleA
+
 #  if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
 
 /* Avoid warnings from gcc -Wcast-function-type.  */
diff --git a/lib/getlogin.c b/lib/getlogin.c
index 5863feb..af93664 100644
--- a/lib/getlogin.c
+++ b/lib/getlogin.c
@@ -25,6 +25,9 @@
 #if defined _WIN32 && ! defined __CYGWIN__
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
+/* Don't assume that UNICODE is not defined.  */
+# undef GetUserName
+# define GetUserName GetUserNameA
 #endif
 
 char *
diff --git a/lib/getlogin_r.c b/lib/getlogin_r.c
index 598a6e4..2506b1b 100644
--- a/lib/getlogin_r.c
+++ b/lib/getlogin_r.c
@@ -30,6 +30,9 @@
 #if defined _WIN32 && ! defined __CYGWIN__
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
+/* Don't assume that UNICODE is not defined.  */
+# undef GetUserName
+# define GetUserName GetUserNameA
 #else
 # if !HAVE_DECL_GETLOGIN
 extern char *getlogin (void);
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index 93914ba..305ab98 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -33,6 +33,10 @@
 
 #ifdef WINDOWS_NATIVE
 
+/* Don't assume that UNICODE is not defined.  */
+# undef LoadLibrary
+# define LoadLibrary LoadLibraryA
+
 # if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
 
 /* Avoid warnings from gcc -Wcast-function-type.  */
diff --git a/lib/isatty.c b/lib/isatty.c
index 4c5b8e3..7c278ec 100644
--- a/lib/isatty.c
+++ b/lib/isatty.c
@@ -39,6 +39,12 @@
 # include <io.h>
 #endif
 
+/* Don't assume that UNICODE is not defined.  */
+#undef LoadLibrary
+#define LoadLibrary LoadLibraryA
+#undef QueryFullProcessImageName
+#define QueryFullProcessImageName QueryFullProcessImageNameA
+
 #if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
 
 /* Avoid warnings from gcc -Wcast-function-type.  */
diff --git a/lib/link.c b/lib/link.c
index 8680e3e..797cdf8 100644
--- a/lib/link.c
+++ b/lib/link.c
@@ -30,6 +30,12 @@
 #  define WIN32_LEAN_AND_MEAN
 #  include <windows.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetModuleHandle
+#  define GetModuleHandle GetModuleHandleA
+#  undef CreateHardLink
+#  define CreateHardLink CreateHardLinkA
+
 #  if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
 
 /* Avoid warnings from gcc -Wcast-function-type.  */
diff --git a/lib/localename.c b/lib/localename.c
index 4046a0b..dc60b07 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -1150,6 +1150,11 @@ extern char * getlocalename_l(int, locale_t);
 # ifndef LOCALE_NAME_MAX_LENGTH
 # define LOCALE_NAME_MAX_LENGTH 85
 # endif
+/* Don't assume that UNICODE is not defined.  */
+# undef GetLocaleInfo
+# define GetLocaleInfo GetLocaleInfoA
+# undef EnumSystemLocales
+# define EnumSystemLocales EnumSystemLocalesA
 #endif
 
 /* We want to use the system's setlocale() function here, not the gnulib
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 9cf78c8..ca1be63 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -195,6 +195,9 @@
 
 #ifdef __CYGWIN__
 # include <windows.h>
+/* Don't assume that UNICODE is not defined.  */
+# undef GetDriveType
+# define GetDriveType GetDriveTypeA
 # define ME_REMOTE me_remote
 /* All cygwin mount points include ':' or start with '//'; so it
    requires a native Windows call to determine remote disks.  */
diff --git a/lib/nonblocking.c b/lib/nonblocking.c
index b354e74..0c4e5f8 100644
--- a/lib/nonblocking.c
+++ b/lib/nonblocking.c
@@ -38,6 +38,10 @@
 #  include <io.h>
 # endif
 
+/* Don't assume that UNICODE is not defined.  */
+# undef GetNamedPipeHandleState
+# define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
 int
 get_nonblocking_flag (int desc)
 {
diff --git a/lib/opendir.c b/lib/opendir.c
index 162ae4a..500fa44 100644
--- a/lib/opendir.c
+++ b/lib/opendir.c
@@ -45,6 +45,16 @@
 # include <fcntl.h>
 #endif
 
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef WIN32_FIND_DATA
+# define WIN32_FIND_DATA WIN32_FIND_DATAA
+# undef GetFullPathName
+# define GetFullPathName GetFullPathNameA
+# undef FindFirstFile
+# define FindFirstFile FindFirstFileA
+#endif
+
 DIR *
 opendir (const char *dir_name)
 {
diff --git a/lib/physmem.c b/lib/physmem.c
index 6f0c5ef..db1bb07 100644
--- a/lib/physmem.c
+++ b/lib/physmem.c
@@ -63,6 +63,10 @@
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
 
+/* Don't assume that UNICODE is not defined.  */
+# undef GetModuleHandle
+# define GetModuleHandle GetModuleHandleA
+
 /* Avoid warnings from gcc -Wcast-function-type.  */
 # define GetProcAddress \
    (void *) GetProcAddress
diff --git a/lib/poll.c b/lib/poll.c
index 53bbafe..61dd639 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -76,6 +76,18 @@
 
 #ifdef WINDOWS_NATIVE
 
+/* Don't assume that UNICODE is not defined.  */
+# undef GetModuleHandle
+# define GetModuleHandle GetModuleHandleA
+# undef PeekConsoleInput
+# define PeekConsoleInput PeekConsoleInputA
+# undef CreateEvent
+# define CreateEvent CreateEventA
+# undef PeekMessage
+# define PeekMessage PeekMessageA
+# undef DispatchMessage
+# define DispatchMessage DispatchMessageA
+
 /* Do *not* use the function WSAPoll
    <https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-wsapoll>
    because there is a bug named “Windows 8 Bugs 309411 - WSAPoll does not
diff --git a/lib/progreloc.c b/lib/progreloc.c
index de00bf6..ab0007c 100644
--- a/lib/progreloc.c
+++ b/lib/progreloc.c
@@ -80,6 +80,12 @@
    one.  */
 extern char * canonicalize_file_name (const char *name);
 
+#if defined WINDOWS_NATIVE
+/* Don't assume that UNICODE is not defined.  */
+# undef GetModuleFileName
+# define GetModuleFileName GetModuleFileNameA
+#endif
+
 /* Pathname support.
    ISSLASH(C)                tests whether C is a directory separator character.
    IS_FILE_NAME_WITH_DIR(P)  tests whether P contains a directory specification.
diff --git a/lib/putenv.c b/lib/putenv.c
index 9e862e6..ce0c752 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -58,6 +58,12 @@ __libc_lock_define_initialized (static, envlock)
 # define UNLOCK
 #endif
 
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef SetEnvironmentVariable
+# define SetEnvironmentVariable SetEnvironmentVariableA
+#endif
+
 static int
 _unsetenv (const char *name)
 {
diff --git a/lib/read.c b/lib/read.c
index 407738b..90d1053 100644
--- a/lib/read.c
+++ b/lib/read.c
@@ -37,6 +37,10 @@
 #  include <io.h>
 # endif
 
+/* Don't assume that UNICODE is not defined.  */
+# undef GetNamedPipeHandleState
+# define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
 # undef read
 
 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
diff --git a/lib/readdir.c b/lib/readdir.c
index 1a02ce4..91a3516 100644
--- a/lib/readdir.c
+++ b/lib/readdir.c
@@ -24,6 +24,10 @@
 
 #include "dirent-private.h"
 
+/* Don't assume that UNICODE is not defined.  */
+#undef FindNextFile
+#define FindNextFile FindNextFileA
+
 struct dirent *
 readdir (DIR *dirp)
 {
diff --git a/lib/relocatable.c b/lib/relocatable.c
index e4b867b..04fb22e 100644
--- a/lib/relocatable.c
+++ b/lib/relocatable.c
@@ -65,6 +65,12 @@
 # include <libintl.h>
 #endif
 
+#if defined _WIN32 && !defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef GetModuleFileName
+# define GetModuleFileName GetModuleFileNameA
+#endif
+
 /* Faked cheap 'bool'.  */
 #undef bool
 #undef false
diff --git a/lib/rename.c b/lib/rename.c
index 09881e8..108dc40 100644
--- a/lib/rename.c
+++ b/lib/rename.c
@@ -39,6 +39,10 @@
 
 # include "dirname.h"
 
+/* Don't assume that UNICODE is not defined.  */
+# undef MoveFileEx
+# define MoveFileEx MoveFileExA
+
 /* Rename the file SRC to DST.  This replacement is necessary on
    Windows, on which the system rename function will not replace
    an existing DST.  */
diff --git a/lib/rewinddir.c b/lib/rewinddir.c
index d8ae714..a18943d 100644
--- a/lib/rewinddir.c
+++ b/lib/rewinddir.c
@@ -23,6 +23,10 @@
 
 #include "dirent-private.h"
 
+/* Don't assume that UNICODE is not defined.  */
+#undef FindFirstFile
+#define FindFirstFile FindFirstFileA
+
 void
 rewinddir (DIR *dirp)
 {
diff --git a/lib/select.c b/lib/select.c
index 4467eae..b2234ea 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -47,6 +47,18 @@
 
 #undef select
 
+/* Don't assume that UNICODE is not defined.  */
+#undef GetModuleHandle
+#define GetModuleHandle GetModuleHandleA
+#undef PeekConsoleInput
+#define PeekConsoleInput PeekConsoleInputA
+#undef CreateEvent
+#define CreateEvent CreateEventA
+#undef PeekMessage
+#define PeekMessage PeekMessageA
+#undef DispatchMessage
+#define DispatchMessage DispatchMessageA
+
 /* Avoid warnings from gcc -Wcast-function-type.  */
 #define GetProcAddress \
   (void *) GetProcAddress
diff --git a/lib/sethostname.c b/lib/sethostname.c
index 96318fb..52064df 100644
--- a/lib/sethostname.c
+++ b/lib/sethostname.c
@@ -103,13 +103,12 @@ sethostname (const char *name, size_t len)
 # include <string.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
+
+/* Don't assume that UNICODE is not defined.  */
+# undef GetComputerNameEx
+# define GetComputerNameEx GetComputerNameExA
+# undef SetComputerNameEx
+# define SetComputerNameEx SetComputerNameExA
 
 /* Set up to LEN chars of NAME as system hostname.
    Return 0 if ok, set errno and return -1 on error. */
diff --git a/lib/socket.c b/lib/socket.c
index 67c6b1e..ebf777f 100644
--- a/lib/socket.c
+++ b/lib/socket.c
@@ -28,6 +28,10 @@
 
 #include "sockets.h"
 
+/* Don't assume that UNICODE is not defined.  */
+#undef WSASocket
+#define WSASocket WSASocketA
+
 int
 rpl_socket (int domain, int type, int protocol)
 {
diff --git a/lib/stat-w32.c b/lib/stat-w32.c
index cca12dd..19bdfaa 100644
--- a/lib/stat-w32.c
+++ b/lib/stat-w32.c
@@ -40,6 +40,12 @@
 #include "pathmax.h"
 #include "verify.h"
 
+/* Don't assume that UNICODE is not defined.  */
+#undef LoadLibrary
+#define LoadLibrary LoadLibraryA
+#undef GetFinalPathNameByHandle
+#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
+
 #if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
 
 /* Avoid warnings from gcc -Wcast-function-type.  */
diff --git a/lib/stat.c b/lib/stat.c
index e074e6a..9d3965d 100644
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -65,6 +65,13 @@ orig_stat (const char *filename, struct stat *buf)
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
 # include "stat-w32.h"
+/* Don't assume that UNICODE is not defined.  */
+# undef WIN32_FIND_DATA
+# define WIN32_FIND_DATA WIN32_FIND_DATAA
+# undef CreateFile
+# define CreateFile CreateFileA
+# undef FindFirstFile
+# define FindFirstFile FindFirstFileA
 #endif
 
 #ifdef WINDOWS_NATIVE
diff --git a/lib/stdio-read.c b/lib/stdio-read.c
index 874c9b1..e63a327 100644
--- a/lib/stdio-read.c
+++ b/lib/stdio-read.c
@@ -43,6 +43,10 @@
 #   include <io.h>
 #  endif
 
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetNamedPipeHandleState
+#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
 #  define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \
   if (ferror (stream))                                                        \
     return (EXPRESSION);                                                      \
diff --git a/lib/stdio-write.c b/lib/stdio-write.c
index 41bc74c..778e7cf 100644
--- a/lib/stdio-write.c
+++ b/lib/stdio-write.c
@@ -45,6 +45,10 @@
 #   include <io.h>
 #  endif
 
+/* Don't assume that UNICODE is not defined.  */
+#  undef GetNamedPipeHandleState
+#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
 #  if GNULIB_NONBLOCKING
 #   define CLEAR_ERRNO \
       errno = 0;
diff --git a/lib/tmpdir.c b/lib/tmpdir.c
index 74ae359..28ff99f 100644
--- a/lib/tmpdir.c
+++ b/lib/tmpdir.c
@@ -49,6 +49,12 @@
 
 #include "pathmax.h"
 
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef GetTempPath
+# define GetTempPath GetTempPathA
+#endif
+
 #if _LIBC
 # define struct_stat64 struct stat64
 #else
diff --git a/lib/tmpfile.c b/lib/tmpfile.c
index 99d6752..667c0f2 100644
--- a/lib/tmpfile.c
+++ b/lib/tmpfile.c
@@ -52,6 +52,14 @@
 #if defined _WIN32 && ! defined __CYGWIN__
 /* A native Windows platforms.  */
 
+/* Don't assume that UNICODE is not defined.  */
+# undef OSVERSIONINFO
+# define OSVERSIONINFO OSVERSIONINFOA
+# undef GetVersionEx
+# define GetVersionEx GetVersionExA
+# undef GetTempPath
+# define GetTempPath GetTempPathA
+
 /* On Windows, opening a file with _O_TEMPORARY has the effect of passing
    the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile(), which has the effect
    of deleting the file when it is closed - even when the program crashes.
diff --git a/lib/uname.c b/lib/uname.c
index d4778a8..cb6dd28 100644
--- a/lib/uname.c
+++ b/lib/uname.c
@@ -22,29 +22,35 @@
 /* This file provides an implementation only for the native Windows API.  */
 #if defined _WIN32 && ! defined __CYGWIN__
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <windows.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+# include <unistd.h>
+# include <windows.h>
 
 /* Mingw headers don't have all the platform codes.  */
-#ifndef VER_PLATFORM_WIN32_CE
-# define VER_PLATFORM_WIN32_CE 3
-#endif
+# ifndef VER_PLATFORM_WIN32_CE
+#  define VER_PLATFORM_WIN32_CE 3
+# endif
 
 /* Some headers don't have all the processor architecture codes.  */
-#ifndef PROCESSOR_ARCHITECTURE_AMD64
-# define PROCESSOR_ARCHITECTURE_AMD64 9
-#endif
-#ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
-# define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
-#endif
+# ifndef PROCESSOR_ARCHITECTURE_AMD64
+#  define PROCESSOR_ARCHITECTURE_AMD64 9
+# endif
+# ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
+#  define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
+# endif
 
 /* Mingw headers don't have the latest processor codes.  */
-#ifndef PROCESSOR_AMD_X8664
-# define PROCESSOR_AMD_X8664 8664
-#endif
+# ifndef PROCESSOR_AMD_X8664
+#  define PROCESSOR_AMD_X8664 8664
+# endif
+
+/* Don't assume that UNICODE is not defined.  */
+# undef OSVERSIONINFO
+# define OSVERSIONINFO OSVERSIONINFOA
+# undef GetVersionEx
+# define GetVersionEx GetVersionExA
 
 int
 uname (struct utsname *buf)
@@ -108,7 +114,7 @@ uname (struct utsname *buf)
     super_version = "";
 
   /* Fill in sysname.  */
-#ifdef __MINGW32__
+# ifdef __MINGW32__
   /* Returns a string compatible with the MSYS uname.exe program,
      so that no further changes are needed to GNU config.guess.
      For example,
@@ -117,9 +123,9 @@ uname (struct utsname *buf)
   sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version,
            (unsigned int) version.dwMajorVersion,
            (unsigned int) version.dwMinorVersion);
-#else
+# else
   sprintf (buf->sysname, "Windows%s", super_version);
-#endif
+# endif
 
   /* Fill in release, version.  */
   /* The MSYS uname.exe programs uses strings from a modified Cygwin runtime:
diff --git a/lib/utime.c b/lib/utime.c
index 77968dc..c35eb16 100644
--- a/lib/utime.c
+++ b/lib/utime.c
@@ -29,6 +29,12 @@
 # include "filename.h"
 # include "malloca.h"
 
+/* Don't assume that UNICODE is not defined.  */
+# undef CreateFile
+# define CreateFile CreateFileA
+# undef GetFileAttributes
+# define GetFileAttributes GetFileAttributesA
+
 int
 _gl_utimens_windows (const char *name, struct timespec ts[2])
 {
diff --git a/lib/windows-cond.c b/lib/windows-cond.c
index 44586a6..45e9b83 100644
--- a/lib/windows-cond.c
+++ b/lib/windows-cond.c
@@ -27,6 +27,10 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#undef CreateEvent
+#define CreateEvent CreateEventA
+
 /* In this file, the waitqueues are implemented as linked lists.  */
 #define glwthread_waitqueue_t glwthread_linked_waitqueue_t
 
diff --git a/lib/windows-rwlock.c b/lib/windows-rwlock.c
index 85a8552..6afb45b 100644
--- a/lib/windows-rwlock.c
+++ b/lib/windows-rwlock.c
@@ -25,6 +25,10 @@
 #include <errno.h>
 #include <stdlib.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#undef CreateEvent
+#define CreateEvent CreateEventA
+
 /* In this file, the waitqueues are implemented as circular arrays.  */
 #define glwthread_waitqueue_t glwthread_carray_waitqueue_t
 
diff --git a/lib/windows-timedmutex.c b/lib/windows-timedmutex.c
index e36f410..788fe40 100644
--- a/lib/windows-timedmutex.c
+++ b/lib/windows-timedmutex.c
@@ -26,6 +26,10 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#undef CreateEvent
+#define CreateEvent CreateEventA
+
 int
 glwthread_timedmutex_init (glwthread_timedmutex_t *mutex)
 {
diff --git a/lib/windows-timedrecmutex.c b/lib/windows-timedrecmutex.c
index 81fcdb6..d244bfd 100644
--- a/lib/windows-timedrecmutex.c
+++ b/lib/windows-timedrecmutex.c
@@ -26,6 +26,10 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#undef CreateEvent
+#define CreateEvent CreateEventA
+
 int
 glwthread_timedrecmutex_init (glwthread_timedrecmutex_t *mutex)
 {
diff --git a/lib/windows-timedrwlock.c b/lib/windows-timedrwlock.c
index 793e8b7..42ad746 100644
--- a/lib/windows-timedrwlock.c
+++ b/lib/windows-timedrwlock.c
@@ -26,6 +26,10 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
+/* Don't assume that UNICODE is not defined.  */
+#undef CreateEvent
+#define CreateEvent CreateEventA
+
 /* In this file, the waitqueues are implemented as linked lists.  */
 #define glwthread_waitqueue_t glwthread_clinked_waitqueue_t
 
diff --git a/lib/write.c b/lib/write.c
index a391283..581e674 100644
--- a/lib/write.c
+++ b/lib/write.c
@@ -43,6 +43,10 @@
 #  include <io.h>
 # endif
 
+/* Don't assume that UNICODE is not defined.  */
+# undef GetNamedPipeHandleState
+# define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
 # undef write
 
 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps
  2020-05-19  6:26 ` [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
  2020-05-28  6:26   ` Steve Lhomme
@ 2020-05-30  9:21   ` Bruno Haible
  1 sibling, 0 replies; 13+ messages in thread
From: Bruno Haible @ 2020-05-30  9:21 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Steve Lhomme

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

Done differently, without reference to WINAPI_FAMILY_PARTITION, through
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=3a1fdff1eebe09d6c4bb87b39d34a1d6f4179eaf

Bruno



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Don't assume that UNICODE is not defined
  2020-05-30  9:16   ` Don't assume that UNICODE is not defined Bruno Haible
@ 2020-05-30 10:57     ` Jeffrey Walton
  2020-05-30 12:43       ` Steve Lhomme
  2020-05-30 12:46     ` Steve Lhomme
  1 sibling, 1 reply; 13+ messages in thread
From: Jeffrey Walton @ 2020-05-30 10:57 UTC (permalink / raw)
  To: Bruno Haible; +Cc: Steve Lhomme, bug-gnulib

On Sat, May 30, 2020 at 5:16 AM Bruno Haible <bruno@clisp.org> wrote:
>
> I wrote:
> > some types depend on
> > whether UNICODE is defined or not [1].
>
> Some functions also depend whether UNICODE is defined or not.
>
> Since UWP applications are meant to defined the macro UNICODE, but we want
> Gnulib to produce the same code, regardless whether UNICODE is defined or not,
> we need to either explicitly use the functions with 'A' suffix (which is ugly)
> or use #defines for redirection.
>
> Fortunately, packages that use gnulib don't need to do this stuff; nor do we
> need to do it in the tests/ directory. Only the gnulib/lib/ directory may
> reasonably be used with -DUNICODE, therefore only the gnulib/lib/ directory
> needs this workaround.

In case it matters, I believe Microsoft keys on _UNICODE, not UNICODE.

Microsoft source files often have something like this (or is it vice-versa):

#ifdef UNICODE
#  ifndef _UNICODE
#    define _UNICODE
#  endif
#endif

Also see https://docs.microsoft.com/en-us/cpp/text/generic-text-mappings-in-tchar-h.

Jeff


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Don't assume that UNICODE is not defined
  2020-05-30 10:57     ` Jeffrey Walton
@ 2020-05-30 12:43       ` Steve Lhomme
  0 siblings, 0 replies; 13+ messages in thread
From: Steve Lhomme @ 2020-05-30 12:43 UTC (permalink / raw)
  To: noloader, Bruno Haible; +Cc: bug-gnulib

I think that's the other way around.

_UNICODE is meant to be used with tchar.h. I found 41 instances in a recent SDK.
UNICODE is the more generic term to chose between ANSI or WIDE API calls (if you don't force them directly). I found 4123 instances in the same SDK.

So IMO the proper way is to use UNICODE, especially if you never use tchar.h.

> On May 30, 2020 12:57 PM Jeffrey Walton <noloader@gmail.com> wrote:
> 
>  
> On Sat, May 30, 2020 at 5:16 AM Bruno Haible <bruno@clisp.org> wrote:
> >
> > I wrote:
> > > some types depend on
> > > whether UNICODE is defined or not [1].
> >
> > Some functions also depend whether UNICODE is defined or not.
> >
> > Since UWP applications are meant to defined the macro UNICODE, but we want
> > Gnulib to produce the same code, regardless whether UNICODE is defined or not,
> > we need to either explicitly use the functions with 'A' suffix (which is ugly)
> > or use #defines for redirection.
> >
> > Fortunately, packages that use gnulib don't need to do this stuff; nor do we
> > need to do it in the tests/ directory. Only the gnulib/lib/ directory may
> > reasonably be used with -DUNICODE, therefore only the gnulib/lib/ directory
> > needs this workaround.
> 
> In case it matters, I believe Microsoft keys on _UNICODE, not UNICODE.
> 
> Microsoft source files often have something like this (or is it vice-versa):
> 
> #ifdef UNICODE
> #  ifndef _UNICODE
> #    define _UNICODE
> #  endif
> #endif
> 
> Also see https://docs.microsoft.com/en-us/cpp/text/generic-text-mappings-in-tchar-h.
> 
> Jeff


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Don't assume that UNICODE is not defined
  2020-05-30  9:16   ` Don't assume that UNICODE is not defined Bruno Haible
  2020-05-30 10:57     ` Jeffrey Walton
@ 2020-05-30 12:46     ` Steve Lhomme
  2020-05-30 14:31       ` Bruno Haible
  1 sibling, 1 reply; 13+ messages in thread
From: Steve Lhomme @ 2020-05-30 12:46 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

Why not use the proper call in the first place rather than use a define ?
It could be useful in a generic header used by all to make sure everyone uses the right thing. But since you need to edit each file it would be cleaner not to use any define at all and use the proper functions and structures directly.

> On May 30, 2020 11:16 AM Bruno Haible <bruno@clisp.org> wrote:
> 
>  
> I wrote:
> > some types depend on
> > whether UNICODE is defined or not [1].
> 
> Some functions also depend whether UNICODE is defined or not.
> 
> Since UWP applications are meant to defined the macro UNICODE, but we want
> Gnulib to produce the same code, regardless whether UNICODE is defined or not,
> we need to either explicitly use the functions with 'A' suffix (which is ugly)
> or use #defines for redirection.
> 
> Fortunately, packages that use gnulib don't need to do this stuff; nor do we
> need to do it in the tests/ directory. Only the gnulib/lib/ directory may
> reasonably be used with -DUNICODE, therefore only the gnulib/lib/ directory
> needs this workaround.
> 
> 
> 2020-05-30  Bruno Haible  <bruno@clisp.org>
> 
> 	Don't assume that UNICODE is not defined.
> 	Many Windows API functions are defined differently (redirecting to a
> 	function with suffix 'W') if the application defines the macro UNICODE
> 	than by default (redirecting to a function with suffix 'A').
> 	* lib/clean-temp.c (OSVERSIONINFO, GetVersionEx): Redirect to the
> 	variant with suffix 'A'.
> 	* lib/dirent-private.h (WIN32_FIND_DATA): Likewise.
> 	* lib/gc-gnulib.c (CryptAcquireContext): Likewise.
> 	* lib/getaddrinfo.c (GetModuleHandle): Likewise.
> 	* lib/getlogin.c (GetUserName): Likewise.
> 	* lib/getlogin_r.c (GetUserName): Likewise.
> 	* lib/gettimeofday.c (LoadLibrary): Likewise.
> 	* lib/isatty.c (LoadLibrary, QueryFullProcessImageName): Likewise.
> 	* lib/link.c (GetModuleHandle, CreateHardLink): Likewise.
> 	* lib/localename.c (GetLocaleInfo, EnumSystemLocales): Likewise.
> 	* lib/mountlist.c (GetDriveType): Likewise.
> 	* lib/nonblocking.c (GetNamedPipeHandleState): Likewise.
> 	* lib/opendir.c (WIN32_FIND_DATA, GetFullPathName, FindFirstFile):
> 	Likewise.
> 	* lib/physmem.c (GetModuleHandle): Likewise.
> 	* lib/poll.c (GetModuleHandle, PeekConsoleInput, CreateEvent,
> 	PeekMessage, DispatchMessage): Likewise.
> 	* lib/progreloc.c (GetModuleFileName): Likewise.
> 	* lib/putenv.c (SetEnvironmentVariable): Likewise.
> 	* lib/read.c (GetNamedPipeHandleState): Likewise.
> 	* lib/readdir.c (FindNextFile): Likewise.
> 	* lib/relocatable.c (GetModuleFileName): Likewise.
> 	* lib/rename.c (MoveFileEx): Likewise.
> 	* lib/rewinddir.c (FindFirstFile): Likewise.
> 	* lib/select.c (GetModuleHandle, PeekConsoleInput, CreateEvent,
> 	PeekMessage, DispatchMessage): Likewise.
> 	* lib/sethostname.c (GetComputerNameEx, SetComputerNameEx): Likewise.
> 	* lib/socket.c (WSASocket): Likewise.
> 	* lib/stat-w32.c (LoadLibrary, GetFinalPathNameByHandle): Likewise.
> 	* lib/stat.c (WIN32_FIND_DATA, CreateFile, FindFirstFile): Likewise.
> 	* lib/stdio-read.c (GetNamedPipeHandleState): Likewise.
> 	* lib/stdio-write.c (GetNamedPipeHandleState): Likewise.
> 	* lib/tmpdir.c (GetTempPath): Likewise.
> 	* lib/tmpfile.c (OSVERSIONINFO, GetVersionEx, GetTempPath): Likewise.
> 	* lib/uname.c (OSVERSIONINFO, GetVersionEx): Likewise.
> 	* lib/utime.c (CreateFile, GetFileAttributes): Likewise.
> 	* lib/windows-cond.c (CreateEvent): Likewise.
> 	* lib/windows-rwlock.c (CreateEvent): Likewise.
> 	* lib/windows-timedmutex.c (CreateEvent): Likewise.
> 	* lib/windows-timedrecmutex.c (CreateEvent): Likewise.
> 	* lib/windows-timedrwlock.c (CreateEvent): Likewise.
> 	* lib/write.c (GetNamedPipeHandleState): Likewise.
> 
> diff --git a/lib/clean-temp.c b/lib/clean-temp.c
> index 8d3cbd9..c57d658 100644
> --- a/lib/clean-temp.c
> +++ b/lib/clean-temp.c
> @@ -66,6 +66,14 @@
>  # define PATH_MAX 1024
>  #endif
>  
> +#if defined _WIN32 && ! defined __CYGWIN__
> +/* Don't assume that UNICODE is not defined.  */
> +# undef OSVERSIONINFO
> +# define OSVERSIONINFO OSVERSIONINFOA
> +# undef GetVersionEx
> +# define GetVersionEx GetVersionExA
> +#endif
> +
>  
>  /* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
>     ensure that while constructing or modifying the data structures, the field
> diff --git a/lib/dirent-private.h b/lib/dirent-private.h
> index 4b4eba4..a3c6844 100644
> --- a/lib/dirent-private.h
> +++ b/lib/dirent-private.h
> @@ -20,6 +20,10 @@
>  #define WIN32_LEAN_AND_MEAN
>  #include <windows.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef WIN32_FIND_DATA
> +#define WIN32_FIND_DATA WIN32_FIND_DATAA
> +
>  struct gl_directory
>  {
>    /* Status, or error code to produce in next readdir() call.
> diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
> index 8e9b88f..84f42e4 100644
> --- a/lib/gc-gnulib.c
> +++ b/lib/gc-gnulib.c
> @@ -89,6 +89,12 @@ HCRYPTPROV g_hProv = 0;
>  # endif
>  #endif
>  
> +#if defined _WIN32 && ! defined __CYGWIN__
> +/* Don't assume that UNICODE is not defined.  */
> +# undef CryptAcquireContext
> +# define CryptAcquireContext CryptAcquireContextA
> +#endif
> +
>  Gc_rc
>  gc_init (void)
>  {
> diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
> index 1db9be8..8d2c01c 100644
> --- a/lib/getaddrinfo.c
> +++ b/lib/getaddrinfo.c
> @@ -86,6 +86,10 @@ freeaddrinfo (struct addrinfo *ai)
>  
>  # ifdef WINDOWS_NATIVE
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#  undef GetModuleHandle
> +#  define GetModuleHandle GetModuleHandleA
> +
>  #  if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
>  
>  /* Avoid warnings from gcc -Wcast-function-type.  */
> diff --git a/lib/getlogin.c b/lib/getlogin.c
> index 5863feb..af93664 100644
> --- a/lib/getlogin.c
> +++ b/lib/getlogin.c
> @@ -25,6 +25,9 @@
>  #if defined _WIN32 && ! defined __CYGWIN__
>  # define WIN32_LEAN_AND_MEAN
>  # include <windows.h>
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetUserName
> +# define GetUserName GetUserNameA
>  #endif
>  
>  char *
> diff --git a/lib/getlogin_r.c b/lib/getlogin_r.c
> index 598a6e4..2506b1b 100644
> --- a/lib/getlogin_r.c
> +++ b/lib/getlogin_r.c
> @@ -30,6 +30,9 @@
>  #if defined _WIN32 && ! defined __CYGWIN__
>  # define WIN32_LEAN_AND_MEAN
>  # include <windows.h>
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetUserName
> +# define GetUserName GetUserNameA
>  #else
>  # if !HAVE_DECL_GETLOGIN
>  extern char *getlogin (void);
> diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
> index 93914ba..305ab98 100644
> --- a/lib/gettimeofday.c
> +++ b/lib/gettimeofday.c
> @@ -33,6 +33,10 @@
>  
>  #ifdef WINDOWS_NATIVE
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef LoadLibrary
> +# define LoadLibrary LoadLibraryA
> +
>  # if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
>  
>  /* Avoid warnings from gcc -Wcast-function-type.  */
> diff --git a/lib/isatty.c b/lib/isatty.c
> index 4c5b8e3..7c278ec 100644
> --- a/lib/isatty.c
> +++ b/lib/isatty.c
> @@ -39,6 +39,12 @@
>  # include <io.h>
>  #endif
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef LoadLibrary
> +#define LoadLibrary LoadLibraryA
> +#undef QueryFullProcessImageName
> +#define QueryFullProcessImageName QueryFullProcessImageNameA
> +
>  #if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
>  
>  /* Avoid warnings from gcc -Wcast-function-type.  */
> diff --git a/lib/link.c b/lib/link.c
> index 8680e3e..797cdf8 100644
> --- a/lib/link.c
> +++ b/lib/link.c
> @@ -30,6 +30,12 @@
>  #  define WIN32_LEAN_AND_MEAN
>  #  include <windows.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#  undef GetModuleHandle
> +#  define GetModuleHandle GetModuleHandleA
> +#  undef CreateHardLink
> +#  define CreateHardLink CreateHardLinkA
> +
>  #  if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
>  
>  /* Avoid warnings from gcc -Wcast-function-type.  */
> diff --git a/lib/localename.c b/lib/localename.c
> index 4046a0b..dc60b07 100644
> --- a/lib/localename.c
> +++ b/lib/localename.c
> @@ -1150,6 +1150,11 @@ extern char * getlocalename_l(int, locale_t);
>  # ifndef LOCALE_NAME_MAX_LENGTH
>  # define LOCALE_NAME_MAX_LENGTH 85
>  # endif
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetLocaleInfo
> +# define GetLocaleInfo GetLocaleInfoA
> +# undef EnumSystemLocales
> +# define EnumSystemLocales EnumSystemLocalesA
>  #endif
>  
>  /* We want to use the system's setlocale() function here, not the gnulib
> diff --git a/lib/mountlist.c b/lib/mountlist.c
> index 9cf78c8..ca1be63 100644
> --- a/lib/mountlist.c
> +++ b/lib/mountlist.c
> @@ -195,6 +195,9 @@
>  
>  #ifdef __CYGWIN__
>  # include <windows.h>
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetDriveType
> +# define GetDriveType GetDriveTypeA
>  # define ME_REMOTE me_remote
>  /* All cygwin mount points include ':' or start with '//'; so it
>     requires a native Windows call to determine remote disks.  */
> diff --git a/lib/nonblocking.c b/lib/nonblocking.c
> index b354e74..0c4e5f8 100644
> --- a/lib/nonblocking.c
> +++ b/lib/nonblocking.c
> @@ -38,6 +38,10 @@
>  #  include <io.h>
>  # endif
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetNamedPipeHandleState
> +# define GetNamedPipeHandleState GetNamedPipeHandleStateA
> +
>  int
>  get_nonblocking_flag (int desc)
>  {
> diff --git a/lib/opendir.c b/lib/opendir.c
> index 162ae4a..500fa44 100644
> --- a/lib/opendir.c
> +++ b/lib/opendir.c
> @@ -45,6 +45,16 @@
>  # include <fcntl.h>
>  #endif
>  
> +#if defined _WIN32 && ! defined __CYGWIN__
> +/* Don't assume that UNICODE is not defined.  */
> +# undef WIN32_FIND_DATA
> +# define WIN32_FIND_DATA WIN32_FIND_DATAA
> +# undef GetFullPathName
> +# define GetFullPathName GetFullPathNameA
> +# undef FindFirstFile
> +# define FindFirstFile FindFirstFileA
> +#endif
> +
>  DIR *
>  opendir (const char *dir_name)
>  {
> diff --git a/lib/physmem.c b/lib/physmem.c
> index 6f0c5ef..db1bb07 100644
> --- a/lib/physmem.c
> +++ b/lib/physmem.c
> @@ -63,6 +63,10 @@
>  # define WIN32_LEAN_AND_MEAN
>  # include <windows.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetModuleHandle
> +# define GetModuleHandle GetModuleHandleA
> +
>  /* Avoid warnings from gcc -Wcast-function-type.  */
>  # define GetProcAddress \
>     (void *) GetProcAddress
> diff --git a/lib/poll.c b/lib/poll.c
> index 53bbafe..61dd639 100644
> --- a/lib/poll.c
> +++ b/lib/poll.c
> @@ -76,6 +76,18 @@
>  
>  #ifdef WINDOWS_NATIVE
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetModuleHandle
> +# define GetModuleHandle GetModuleHandleA
> +# undef PeekConsoleInput
> +# define PeekConsoleInput PeekConsoleInputA
> +# undef CreateEvent
> +# define CreateEvent CreateEventA
> +# undef PeekMessage
> +# define PeekMessage PeekMessageA
> +# undef DispatchMessage
> +# define DispatchMessage DispatchMessageA
> +
>  /* Do *not* use the function WSAPoll
>     <https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-wsapoll>
>     because there is a bug named “Windows 8 Bugs 309411 - WSAPoll does not
> diff --git a/lib/progreloc.c b/lib/progreloc.c
> index de00bf6..ab0007c 100644
> --- a/lib/progreloc.c
> +++ b/lib/progreloc.c
> @@ -80,6 +80,12 @@
>     one.  */
>  extern char * canonicalize_file_name (const char *name);
>  
> +#if defined WINDOWS_NATIVE
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetModuleFileName
> +# define GetModuleFileName GetModuleFileNameA
> +#endif
> +
>  /* Pathname support.
>     ISSLASH(C)                tests whether C is a directory separator character.
>     IS_FILE_NAME_WITH_DIR(P)  tests whether P contains a directory specification.
> diff --git a/lib/putenv.c b/lib/putenv.c
> index 9e862e6..ce0c752 100644
> --- a/lib/putenv.c
> +++ b/lib/putenv.c
> @@ -58,6 +58,12 @@ __libc_lock_define_initialized (static, envlock)
>  # define UNLOCK
>  #endif
>  
> +#if defined _WIN32 && ! defined __CYGWIN__
> +/* Don't assume that UNICODE is not defined.  */
> +# undef SetEnvironmentVariable
> +# define SetEnvironmentVariable SetEnvironmentVariableA
> +#endif
> +
>  static int
>  _unsetenv (const char *name)
>  {
> diff --git a/lib/read.c b/lib/read.c
> index 407738b..90d1053 100644
> --- a/lib/read.c
> +++ b/lib/read.c
> @@ -37,6 +37,10 @@
>  #  include <io.h>
>  # endif
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetNamedPipeHandleState
> +# define GetNamedPipeHandleState GetNamedPipeHandleStateA
> +
>  # undef read
>  
>  # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
> diff --git a/lib/readdir.c b/lib/readdir.c
> index 1a02ce4..91a3516 100644
> --- a/lib/readdir.c
> +++ b/lib/readdir.c
> @@ -24,6 +24,10 @@
>  
>  #include "dirent-private.h"
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef FindNextFile
> +#define FindNextFile FindNextFileA
> +
>  struct dirent *
>  readdir (DIR *dirp)
>  {
> diff --git a/lib/relocatable.c b/lib/relocatable.c
> index e4b867b..04fb22e 100644
> --- a/lib/relocatable.c
> +++ b/lib/relocatable.c
> @@ -65,6 +65,12 @@
>  # include <libintl.h>
>  #endif
>  
> +#if defined _WIN32 && !defined __CYGWIN__
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetModuleFileName
> +# define GetModuleFileName GetModuleFileNameA
> +#endif
> +
>  /* Faked cheap 'bool'.  */
>  #undef bool
>  #undef false
> diff --git a/lib/rename.c b/lib/rename.c
> index 09881e8..108dc40 100644
> --- a/lib/rename.c
> +++ b/lib/rename.c
> @@ -39,6 +39,10 @@
>  
>  # include "dirname.h"
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef MoveFileEx
> +# define MoveFileEx MoveFileExA
> +
>  /* Rename the file SRC to DST.  This replacement is necessary on
>     Windows, on which the system rename function will not replace
>     an existing DST.  */
> diff --git a/lib/rewinddir.c b/lib/rewinddir.c
> index d8ae714..a18943d 100644
> --- a/lib/rewinddir.c
> +++ b/lib/rewinddir.c
> @@ -23,6 +23,10 @@
>  
>  #include "dirent-private.h"
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef FindFirstFile
> +#define FindFirstFile FindFirstFileA
> +
>  void
>  rewinddir (DIR *dirp)
>  {
> diff --git a/lib/select.c b/lib/select.c
> index 4467eae..b2234ea 100644
> --- a/lib/select.c
> +++ b/lib/select.c
> @@ -47,6 +47,18 @@
>  
>  #undef select
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef GetModuleHandle
> +#define GetModuleHandle GetModuleHandleA
> +#undef PeekConsoleInput
> +#define PeekConsoleInput PeekConsoleInputA
> +#undef CreateEvent
> +#define CreateEvent CreateEventA
> +#undef PeekMessage
> +#define PeekMessage PeekMessageA
> +#undef DispatchMessage
> +#define DispatchMessage DispatchMessageA
> +
>  /* Avoid warnings from gcc -Wcast-function-type.  */
>  #define GetProcAddress \
>    (void *) GetProcAddress
> diff --git a/lib/sethostname.c b/lib/sethostname.c
> index 96318fb..52064df 100644
> --- a/lib/sethostname.c
> +++ b/lib/sethostname.c
> @@ -103,13 +103,12 @@ sethostname (const char *name, size_t len)
>  # include <string.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
> +
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetComputerNameEx
> +# define GetComputerNameEx GetComputerNameExA
> +# undef SetComputerNameEx
> +# define SetComputerNameEx SetComputerNameExA
>  
>  /* Set up to LEN chars of NAME as system hostname.
>     Return 0 if ok, set errno and return -1 on error. */
> diff --git a/lib/socket.c b/lib/socket.c
> index 67c6b1e..ebf777f 100644
> --- a/lib/socket.c
> +++ b/lib/socket.c
> @@ -28,6 +28,10 @@
>  
>  #include "sockets.h"
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef WSASocket
> +#define WSASocket WSASocketA
> +
>  int
>  rpl_socket (int domain, int type, int protocol)
>  {
> diff --git a/lib/stat-w32.c b/lib/stat-w32.c
> index cca12dd..19bdfaa 100644
> --- a/lib/stat-w32.c
> +++ b/lib/stat-w32.c
> @@ -40,6 +40,12 @@
>  #include "pathmax.h"
>  #include "verify.h"
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef LoadLibrary
> +#define LoadLibrary LoadLibraryA
> +#undef GetFinalPathNameByHandle
> +#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
> +
>  #if !(_WIN32_WINNT >= _WIN32_WINNT_VISTA)
>  
>  /* Avoid warnings from gcc -Wcast-function-type.  */
> diff --git a/lib/stat.c b/lib/stat.c
> index e074e6a..9d3965d 100644
> --- a/lib/stat.c
> +++ b/lib/stat.c
> @@ -65,6 +65,13 @@ orig_stat (const char *filename, struct stat *buf)
>  # define WIN32_LEAN_AND_MEAN
>  # include <windows.h>
>  # include "stat-w32.h"
> +/* Don't assume that UNICODE is not defined.  */
> +# undef WIN32_FIND_DATA
> +# define WIN32_FIND_DATA WIN32_FIND_DATAA
> +# undef CreateFile
> +# define CreateFile CreateFileA
> +# undef FindFirstFile
> +# define FindFirstFile FindFirstFileA
>  #endif
>  
>  #ifdef WINDOWS_NATIVE
> diff --git a/lib/stdio-read.c b/lib/stdio-read.c
> index 874c9b1..e63a327 100644
> --- a/lib/stdio-read.c
> +++ b/lib/stdio-read.c
> @@ -43,6 +43,10 @@
>  #   include <io.h>
>  #  endif
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#  undef GetNamedPipeHandleState
> +#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
> +
>  #  define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \
>    if (ferror (stream))                                                        \
>      return (EXPRESSION);                                                      \
> diff --git a/lib/stdio-write.c b/lib/stdio-write.c
> index 41bc74c..778e7cf 100644
> --- a/lib/stdio-write.c
> +++ b/lib/stdio-write.c
> @@ -45,6 +45,10 @@
>  #   include <io.h>
>  #  endif
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#  undef GetNamedPipeHandleState
> +#  define GetNamedPipeHandleState GetNamedPipeHandleStateA
> +
>  #  if GNULIB_NONBLOCKING
>  #   define CLEAR_ERRNO \
>        errno = 0;
> diff --git a/lib/tmpdir.c b/lib/tmpdir.c
> index 74ae359..28ff99f 100644
> --- a/lib/tmpdir.c
> +++ b/lib/tmpdir.c
> @@ -49,6 +49,12 @@
>  
>  #include "pathmax.h"
>  
> +#if defined _WIN32 && ! defined __CYGWIN__
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetTempPath
> +# define GetTempPath GetTempPathA
> +#endif
> +
>  #if _LIBC
>  # define struct_stat64 struct stat64
>  #else
> diff --git a/lib/tmpfile.c b/lib/tmpfile.c
> index 99d6752..667c0f2 100644
> --- a/lib/tmpfile.c
> +++ b/lib/tmpfile.c
> @@ -52,6 +52,14 @@
>  #if defined _WIN32 && ! defined __CYGWIN__
>  /* A native Windows platforms.  */
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef OSVERSIONINFO
> +# define OSVERSIONINFO OSVERSIONINFOA
> +# undef GetVersionEx
> +# define GetVersionEx GetVersionExA
> +# undef GetTempPath
> +# define GetTempPath GetTempPathA
> +
>  /* On Windows, opening a file with _O_TEMPORARY has the effect of passing
>     the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile(), which has the effect
>     of deleting the file when it is closed - even when the program crashes.
> diff --git a/lib/uname.c b/lib/uname.c
> index d4778a8..cb6dd28 100644
> --- a/lib/uname.c
> +++ b/lib/uname.c
> @@ -22,29 +22,35 @@
>  /* This file provides an implementation only for the native Windows API.  */
>  #if defined _WIN32 && ! defined __CYGWIN__
>  
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <string.h>
> -#include <unistd.h>
> -#include <windows.h>
> +# include <stdio.h>
> +# include <stdlib.h>
> +# include <string.h>
> +# include <unistd.h>
> +# include <windows.h>
>  
>  /* Mingw headers don't have all the platform codes.  */
> -#ifndef VER_PLATFORM_WIN32_CE
> -# define VER_PLATFORM_WIN32_CE 3
> -#endif
> +# ifndef VER_PLATFORM_WIN32_CE
> +#  define VER_PLATFORM_WIN32_CE 3
> +# endif
>  
>  /* Some headers don't have all the processor architecture codes.  */
> -#ifndef PROCESSOR_ARCHITECTURE_AMD64
> -# define PROCESSOR_ARCHITECTURE_AMD64 9
> -#endif
> -#ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
> -# define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
> -#endif
> +# ifndef PROCESSOR_ARCHITECTURE_AMD64
> +#  define PROCESSOR_ARCHITECTURE_AMD64 9
> +# endif
> +# ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
> +#  define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
> +# endif
>  
>  /* Mingw headers don't have the latest processor codes.  */
> -#ifndef PROCESSOR_AMD_X8664
> -# define PROCESSOR_AMD_X8664 8664
> -#endif
> +# ifndef PROCESSOR_AMD_X8664
> +#  define PROCESSOR_AMD_X8664 8664
> +# endif
> +
> +/* Don't assume that UNICODE is not defined.  */
> +# undef OSVERSIONINFO
> +# define OSVERSIONINFO OSVERSIONINFOA
> +# undef GetVersionEx
> +# define GetVersionEx GetVersionExA
>  
>  int
>  uname (struct utsname *buf)
> @@ -108,7 +114,7 @@ uname (struct utsname *buf)
>      super_version = "";
>  
>    /* Fill in sysname.  */
> -#ifdef __MINGW32__
> +# ifdef __MINGW32__
>    /* Returns a string compatible with the MSYS uname.exe program,
>       so that no further changes are needed to GNU config.guess.
>       For example,
> @@ -117,9 +123,9 @@ uname (struct utsname *buf)
>    sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version,
>             (unsigned int) version.dwMajorVersion,
>             (unsigned int) version.dwMinorVersion);
> -#else
> +# else
>    sprintf (buf->sysname, "Windows%s", super_version);
> -#endif
> +# endif
>  
>    /* Fill in release, version.  */
>    /* The MSYS uname.exe programs uses strings from a modified Cygwin runtime:
> diff --git a/lib/utime.c b/lib/utime.c
> index 77968dc..c35eb16 100644
> --- a/lib/utime.c
> +++ b/lib/utime.c
> @@ -29,6 +29,12 @@
>  # include "filename.h"
>  # include "malloca.h"
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef CreateFile
> +# define CreateFile CreateFileA
> +# undef GetFileAttributes
> +# define GetFileAttributes GetFileAttributesA
> +
>  int
>  _gl_utimens_windows (const char *name, struct timespec ts[2])
>  {
> diff --git a/lib/windows-cond.c b/lib/windows-cond.c
> index 44586a6..45e9b83 100644
> --- a/lib/windows-cond.c
> +++ b/lib/windows-cond.c
> @@ -27,6 +27,10 @@
>  #include <stdlib.h>
>  #include <sys/time.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef CreateEvent
> +#define CreateEvent CreateEventA
> +
>  /* In this file, the waitqueues are implemented as linked lists.  */
>  #define glwthread_waitqueue_t glwthread_linked_waitqueue_t
>  
> diff --git a/lib/windows-rwlock.c b/lib/windows-rwlock.c
> index 85a8552..6afb45b 100644
> --- a/lib/windows-rwlock.c
> +++ b/lib/windows-rwlock.c
> @@ -25,6 +25,10 @@
>  #include <errno.h>
>  #include <stdlib.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef CreateEvent
> +#define CreateEvent CreateEventA
> +
>  /* In this file, the waitqueues are implemented as circular arrays.  */
>  #define glwthread_waitqueue_t glwthread_carray_waitqueue_t
>  
> diff --git a/lib/windows-timedmutex.c b/lib/windows-timedmutex.c
> index e36f410..788fe40 100644
> --- a/lib/windows-timedmutex.c
> +++ b/lib/windows-timedmutex.c
> @@ -26,6 +26,10 @@
>  #include <stdlib.h>
>  #include <sys/time.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef CreateEvent
> +#define CreateEvent CreateEventA
> +
>  int
>  glwthread_timedmutex_init (glwthread_timedmutex_t *mutex)
>  {
> diff --git a/lib/windows-timedrecmutex.c b/lib/windows-timedrecmutex.c
> index 81fcdb6..d244bfd 100644
> --- a/lib/windows-timedrecmutex.c
> +++ b/lib/windows-timedrecmutex.c
> @@ -26,6 +26,10 @@
>  #include <stdlib.h>
>  #include <sys/time.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef CreateEvent
> +#define CreateEvent CreateEventA
> +
>  int
>  glwthread_timedrecmutex_init (glwthread_timedrecmutex_t *mutex)
>  {
> diff --git a/lib/windows-timedrwlock.c b/lib/windows-timedrwlock.c
> index 793e8b7..42ad746 100644
> --- a/lib/windows-timedrwlock.c
> +++ b/lib/windows-timedrwlock.c
> @@ -26,6 +26,10 @@
>  #include <stdlib.h>
>  #include <sys/time.h>
>  
> +/* Don't assume that UNICODE is not defined.  */
> +#undef CreateEvent
> +#define CreateEvent CreateEventA
> +
>  /* In this file, the waitqueues are implemented as linked lists.  */
>  #define glwthread_waitqueue_t glwthread_clinked_waitqueue_t
>  
> diff --git a/lib/write.c b/lib/write.c
> index a391283..581e674 100644
> --- a/lib/write.c
> +++ b/lib/write.c
> @@ -43,6 +43,10 @@
>  #  include <io.h>
>  # endif
>  
> +/* Don't assume that UNICODE is not defined.  */
> +# undef GetNamedPipeHandleState
> +# define GetNamedPipeHandleState GetNamedPipeHandleStateA
> +
>  # undef write
>  
>  # if HAVE_MSVC_INVALID_PARAMETER_HANDLER


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Don't assume that UNICODE is not defined
  2020-05-30 12:46     ` Steve Lhomme
@ 2020-05-30 14:31       ` Bruno Haible
  2020-05-30 14:46         ` Steve Lhomme
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Haible @ 2020-05-30 14:31 UTC (permalink / raw)
  To: Steve Lhomme; +Cc: bug-gnulib

Steve Lhomme wrote:
> Why not use the proper call in the first place rather than use a define ?
> It could be useful in a generic header used by all to make sure everyone
> uses the right thing. But since you need to edit each file it would be
> cleaner not to use any define at all and use the proper functions and
> structures directly.

It would be possible. But
  - It is ugly.
  - The correct search term on microsoft.com, stackoverflow.com, etc. is
    'LoadLibrary', not 'LoadLibraryA'. Let's speak the same language as
    everyone else is speaking.

Bruno



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Don't assume that UNICODE is not defined
  2020-05-30 14:31       ` Bruno Haible
@ 2020-05-30 14:46         ` Steve Lhomme
  2020-05-30 15:43           ` Bruno Haible
  0 siblings, 1 reply; 13+ messages in thread
From: Steve Lhomme @ 2020-05-30 14:46 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib

> On May 30, 2020 4:31 PM Bruno Haible <bruno@clisp.org> wrote:
> 
>  
> Steve Lhomme wrote:
> > Why not use the proper call in the first place rather than use a define ?
> > It could be useful in a generic header used by all to make sure everyone
> > uses the right thing. But since you need to edit each file it would be
> > cleaner not to use any define at all and use the proper functions and
> > structures directly.
> 
> It would be possible. But
>   - It is ugly.
>   - The correct search term on microsoft.com, stackoverflow.com, etc. is
>     'LoadLibrary', not 'LoadLibraryA'. Let's speak the same language as
>     everyone else is speaking.

Microsoft.com doesn't document the function as LoadLibrary anymore. There is LoadLibraryA and LoadLibraryW.
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw

It even says the following:
The libloaderapi.h header defines LoadLibrary as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Given the name of the header that's not what should be used from now on. Using the old names gives a sense of safety you don't actually have. Looking at the code I would assume, like any currently maintained code, that the default is to call UNICODE API's. But I don't find any mention of WideCharToMultiByte or CP_UTF8 in the code. And from the patch you did it's quite the opposite.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Don't assume that UNICODE is not defined
  2020-05-30 14:46         ` Steve Lhomme
@ 2020-05-30 15:43           ` Bruno Haible
  0 siblings, 0 replies; 13+ messages in thread
From: Bruno Haible @ 2020-05-30 15:43 UTC (permalink / raw)
  To: Steve Lhomme; +Cc: bug-gnulib

Steve Lhomme wrote:
> Microsoft.com doesn't document the function as LoadLibrary anymore. There is LoadLibraryA and LoadLibraryW.
> https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya
> https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw

The text still talks mostly about 'LoadLibrary'. Likewise in
https://docs.microsoft.com/en-us/windows/win32/dlls/run-time-dynamic-linking

Bruno



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-05-30 15:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19  6:26 [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Steve Lhomme
2020-05-19  6:26 ` [PATCH 2/2] stat: do not use LoadLibrary when built for Windows Store apps Steve Lhomme
2020-05-28  6:26   ` Steve Lhomme
2020-05-30  9:21   ` Bruno Haible
2020-05-28  0:43 ` [PATCH 1/2] stat: use a CHAR instead of TCHAR with GetFinalPathNameByHandleA Bruno Haible
2020-05-28  1:07   ` Jeffrey Walton
2020-05-30  9:16   ` Don't assume that UNICODE is not defined Bruno Haible
2020-05-30 10:57     ` Jeffrey Walton
2020-05-30 12:43       ` Steve Lhomme
2020-05-30 12:46     ` Steve Lhomme
2020-05-30 14:31       ` Bruno Haible
2020-05-30 14:46         ` Steve Lhomme
2020-05-30 15:43           ` 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).