summaryrefslogtreecommitdiffstats
path: root/src/port/win32fdatasync.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
commit293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch)
treefc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /src/port/win32fdatasync.c
parentInitial commit. (diff)
downloadpostgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz
postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/port/win32fdatasync.c')
-rw-r--r--src/port/win32fdatasync.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/port/win32fdatasync.c b/src/port/win32fdatasync.c
new file mode 100644
index 0000000..ad03880
--- /dev/null
+++ b/src/port/win32fdatasync.c
@@ -0,0 +1,51 @@
+/*-------------------------------------------------------------------------
+ *
+ * win32fdatasync.c
+ * Win32 fdatasync() replacement
+ *
+ *
+ * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ *
+ * src/port/win32fdatasync.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifdef FRONTEND
+#include "postgres_fe.h"
+#else
+#include "postgres.h"
+#endif
+
+#include "port/win32ntdll.h"
+
+int
+fdatasync(int fd)
+{
+ IO_STATUS_BLOCK iosb;
+ NTSTATUS status;
+ HANDLE handle;
+
+ handle = (HANDLE) _get_osfhandle(fd);
+ if (handle == INVALID_HANDLE_VALUE)
+ {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (initialize_ntdll() < 0)
+ return -1;
+
+ memset(&iosb, 0, sizeof(iosb));
+ status = pg_NtFlushBuffersFileEx(handle,
+ FLUSH_FLAGS_FILE_DATA_SYNC_ONLY,
+ NULL,
+ 0,
+ &iosb);
+
+ if (NT_SUCCESS(status))
+ return 0;
+
+ _dosmaperr(pg_RtlNtStatusToDosError(status));
+ return -1;
+}