Git 2.42-rc2
[alt-git.git] / compat / win32 / flush.c
blob291f90ea9406ba655456d0d5f50b05adb3a96404
1 #include "git-compat-util.h"
2 #include <winternl.h>
3 #include "lazyload.h"
5 int win32_fsync_no_flush(int fd)
7 IO_STATUS_BLOCK io_status;
9 #define FLUSH_FLAGS_FILE_DATA_ONLY 1
11 DECLARE_PROC_ADDR(ntdll.dll, NTSTATUS, NTAPI, NtFlushBuffersFileEx,
12 HANDLE FileHandle, ULONG Flags, PVOID Parameters, ULONG ParameterSize,
13 PIO_STATUS_BLOCK IoStatusBlock);
15 if (!INIT_PROC_ADDR(NtFlushBuffersFileEx)) {
16 errno = ENOSYS;
17 return -1;
20 memset(&io_status, 0, sizeof(io_status));
21 if (NtFlushBuffersFileEx((HANDLE)_get_osfhandle(fd), FLUSH_FLAGS_FILE_DATA_ONLY,
22 NULL, 0, &io_status)) {
23 errno = EINVAL;
24 return -1;
27 return 0;