+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.
+
2020-05-30 Bruno Haible <bruno@clisp.org>
physmem: Fix compilation errors on MSVC.
# 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
#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.
# 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)
{
# 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. */
#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 *
#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);
#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. */
# 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. */
# 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. */
# 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
#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. */
# include <io.h>
# endif
+/* Don't assume that UNICODE is not defined. */
+# undef GetNamedPipeHandleState
+# define GetNamedPipeHandleState GetNamedPipeHandleStateA
+
int
get_nonblocking_flag (int desc)
{
# 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)
{
# 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
#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
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.
# 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)
{
# 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
#include "dirent-private.h"
+/* Don't assume that UNICODE is not defined. */
+#undef FindNextFile
+#define FindNextFile FindNextFileA
+
struct dirent *
readdir (DIR *dirp)
{
# 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
# 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. */
#include "dirent-private.h"
+/* Don't assume that UNICODE is not defined. */
+#undef FindFirstFile
+#define FindFirstFile FindFirstFileA
+
void
rewinddir (DIR *dirp)
{
#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
# 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. */
#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)
{
#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. */
# 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
# 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); \
# 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;
#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
#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.
/* 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)
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,
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:
# 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])
{
#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
#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
#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)
{
#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)
{
#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
# 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