Debian Codegraph @

src/port/win32fdatasync.c

raw
1 /*-------------------------------------------------------------------------
2 *
3 * win32fdatasync.c
4 * Win32 fdatasync() replacement
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 *
9 * src/port/win32fdatasync.c
10 *
11 *-------------------------------------------------------------------------
12 */
13
14 #ifdef FRONTEND
15 #include "postgres_fe.h"
16 #else
17 #include "postgres.h"
18 #endif
19
20 #include "port/win32ntdll.h"
21
22 int
23 fdatasync(int fd)
24 {
25 IO_STATUS_BLOCK iosb;
26 NTSTATUS status;
27 HANDLE handle;
28
29 handle = (HANDLE) _get_osfhandle(fd);
30 if (handle == INVALID_HANDLE_VALUE)
31 {
32 errno = EBADF;
33 return -1;
34 }
35
36 if (initialize_ntdll() < 0)
37 return -1;
38
39 memset(&iosb, 0, sizeof(iosb));
40 status = pg_NtFlushBuffersFileEx(handle,
41 FLUSH_FLAGS_FILE_DATA_SYNC_ONLY,
42 NULL,
43 0,
44 &iosb);
45
46 if (NT_SUCCESS(status))
47 return 0;
48
49 _dosmaperr(pg_RtlNtStatusToDosError(status));
50 return -1;
51 }