From ab1fc94a5bc38d00ba4fac7cbe50b06d35459349 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 8 May 2021 10:12:41 +0300 Subject: [PATCH] mdbx-windows: fix build for Windows XP/2000 (`_WIN32_WINNT` < 0x0600). Related to https://github.com/erthink/libmdbx/issues/155 Change-Id: Ibd795817e05b6da39ef270ce7b55b31d963d07b0 --- .github/actions/spelling/expect.txt | 2 ++ src/mdbx.c++ | 7 +++++ src/osal.c | 4 +++ src/osal.h | 48 ++++++++++++++++++++++++++++- test/base.h | 3 ++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index c26d3257..da1e08c8 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -832,6 +832,7 @@ LMEM LNK lnps lntdll +LOBYTE localtime lockf lockfile @@ -844,6 +845,7 @@ longlived LONGLONG lowerbound lowerboundvalue +LOWORD LPCSTR LPDWORD LPFILETIME diff --git a/src/mdbx.c++ b/src/mdbx.c++ index 676f0966..ce7a8ae3 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -216,6 +216,13 @@ template <> struct path_to_pchar { #if defined(_WIN32) || defined(_WIN64) +#ifndef WC_ERR_INVALID_CHARS +static const DWORD WC_ERR_INVALID_CHARS = + (6 /* Windows Vista */ <= /* MajorVersion */ LOBYTE(LOWORD(GetVersion()))) + ? 0x00000080 + : 0; +#endif /* WC_ERR_INVALID_CHARS */ + template <> struct path_to_pchar { std::string str; path_to_pchar(const std::wstring &path) { diff --git a/src/osal.c b/src/osal.c index 0f03b850..08e0d687 100644 --- a/src/osal.c +++ b/src/osal.c @@ -133,6 +133,10 @@ typedef struct _FILE_PROVIDER_EXTERNAL_INFO_V1 { CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 196, METHOD_BUFFERED, FILE_ANY_ACCESS) #endif +#ifndef ERROR_NOT_CAPABLE +#define ERROR_NOT_CAPABLE 775L +#endif + #endif /* _WIN32 || _WIN64 */ /*----------------------------------------------------------------------------*/ diff --git a/src/osal.h b/src/osal.h index d31a254f..b7c476f2 100644 --- a/src/osal.h +++ b/src/osal.h @@ -145,7 +145,7 @@ __extern_C key_t ftok(const char *, int); #if defined(_WIN32) || defined(_WIN64) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN -#endif +#endif /* WIN32_LEAN_AND_MEAN */ #include #include #include @@ -837,6 +837,52 @@ MDBX_INTERNAL_VAR MDBX_srwlock_function mdbx_srwlock_Init, mdbx_srwlock_AcquireShared, mdbx_srwlock_ReleaseShared, mdbx_srwlock_AcquireExclusive, mdbx_srwlock_ReleaseExclusive; +#if _WIN32_WINNT < 0x0600 /* prior to Windows Vista */ +typedef enum _FILE_INFO_BY_HANDLE_CLASS { + FileBasicInfo, + FileStandardInfo, + FileNameInfo, + FileRenameInfo, + FileDispositionInfo, + FileAllocationInfo, + FileEndOfFileInfo, + FileStreamInfo, + FileCompressionInfo, + FileAttributeTagInfo, + FileIdBothDirectoryInfo, + FileIdBothDirectoryRestartInfo, + FileIoPriorityHintInfo, + FileRemoteProtocolInfo, + MaximumFileInfoByHandleClass +} FILE_INFO_BY_HANDLE_CLASS, + *PFILE_INFO_BY_HANDLE_CLASS; + +typedef struct _FILE_END_OF_FILE_INFO { + LARGE_INTEGER EndOfFile; +} FILE_END_OF_FILE_INFO, *PFILE_END_OF_FILE_INFO; + +#define REMOTE_PROTOCOL_INFO_FLAG_LOOPBACK 0x00000001 +#define REMOTE_PROTOCOL_INFO_FLAG_OFFLINE 0x00000002 + +typedef struct _FILE_REMOTE_PROTOCOL_INFO { + USHORT StructureVersion; + USHORT StructureSize; + DWORD Protocol; + USHORT ProtocolMajorVersion; + USHORT ProtocolMinorVersion; + USHORT ProtocolRevision; + USHORT Reserved; + DWORD Flags; + struct { + DWORD Reserved[8]; + } GenericReserved; + struct { + DWORD Reserved[16]; + } ProtocolSpecificReserved; +} FILE_REMOTE_PROTOCOL_INFO, *PFILE_REMOTE_PROTOCOL_INFO; + +#endif /* _WIN32_WINNT < 0x0600 (prior to Windows Vista) */ + typedef BOOL(WINAPI *MDBX_GetFileInformationByHandleEx)( _In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass, _Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize); diff --git a/test/base.h b/test/base.h index 18bbee91..be8e05e3 100644 --- a/test/base.h +++ b/test/base.h @@ -19,6 +19,9 @@ #endif #if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0601 /* Windows 7 */ +#endif #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #pragma warning(push, 1)