mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx-windows: use SetFileInformationByHandle() when available.
Change-Id: I27d9d4271d4328947ad68cdf30af61a31978b4f9
This commit is contained in:
parent
e3ff44d01b
commit
624968b74c
@ -663,6 +663,7 @@ MDBX_srwlock_function mdbx_srwlock_Init, mdbx_srwlock_AcquireShared,
|
||||
MDBX_GetFileInformationByHandleEx mdbx_GetFileInformationByHandleEx;
|
||||
MDBX_GetVolumeInformationByHandleW mdbx_GetVolumeInformationByHandleW;
|
||||
MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
||||
MDBX_SetFileInformationByHandle mdbx_SetFileInformationByHandle;
|
||||
MDBX_NtFsControlFile mdbx_NtFsControlFile;
|
||||
|
||||
static void mdbx_winnt_import(void) {
|
||||
@ -699,6 +700,10 @@ static void mdbx_winnt_import(void) {
|
||||
(MDBX_GetFinalPathNameByHandleW)GetProcAddress(
|
||||
hKernel32dll, "GetFinalPathNameByHandleW");
|
||||
|
||||
mdbx_SetFileInformationByHandle =
|
||||
(MDBX_SetFileInformationByHandle)GetProcAddress(
|
||||
hKernel32dll, "SetFileInformationByHandle");
|
||||
|
||||
const HINSTANCE hNtdll = GetModuleHandleA("ntdll.dll");
|
||||
mdbx_NtFsControlFile =
|
||||
(MDBX_NtFsControlFile)GetProcAddress(hNtdll, "NtFsControlFile");
|
||||
|
20
src/osal.c
20
src/osal.c
@ -741,11 +741,21 @@ int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length) {
|
||||
|
||||
int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = length;
|
||||
return (SetFilePointerEx(fd, li, NULL, FILE_BEGIN) && SetEndOfFile(fd))
|
||||
? MDBX_SUCCESS
|
||||
: GetLastError();
|
||||
if (mdbx_SetFileInformationByHandle) {
|
||||
FILE_END_OF_FILE_INFO EndOfFileInfo;
|
||||
EndOfFileInfo.EndOfFile.QuadPart = length;
|
||||
return mdbx_SetFileInformationByHandle(fd, FileEndOfFileInfo,
|
||||
&EndOfFileInfo,
|
||||
sizeof(FILE_END_OF_FILE_INFO))
|
||||
? MDBX_SUCCESS
|
||||
: GetLastError();
|
||||
} else {
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = length;
|
||||
return (SetFilePointerEx(fd, li, NULL, FILE_BEGIN) && SetEndOfFile(fd))
|
||||
? MDBX_SUCCESS
|
||||
: GetLastError();
|
||||
}
|
||||
#else
|
||||
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||
|
@ -627,6 +627,12 @@ typedef DWORD(WINAPI *MDBX_GetFinalPathNameByHandleW)(_In_ HANDLE hFile,
|
||||
_In_ DWORD dwFlags);
|
||||
extern MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
||||
|
||||
typedef BOOL(WINAPI *MDBX_SetFileInformationByHandle)(
|
||||
_In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
|
||||
_Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize);
|
||||
|
||||
extern MDBX_SetFileInformationByHandle mdbx_SetFileInformationByHandle;
|
||||
|
||||
typedef NTSTATUS(NTAPI *MDBX_NtFsControlFile)(
|
||||
IN HANDLE FileHandle, IN OUT HANDLE Event,
|
||||
IN OUT PVOID /* PIO_APC_ROUTINE */ ApcRoutine, IN OUT PVOID ApcContext,
|
||||
|
Loading…
Reference in New Issue
Block a user