aboutsummaryrefslogtreecommitdiff
path: root/src/port/win32fdatasync.c
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2022-08-05 16:10:05 +1200
committerThomas Munro <tmunro@postgresql.org>2022-08-05 16:37:38 +1200
commitd2e150831af85fd30742f551a497db6639d91d0b (patch)
treed05fc4b757d8af7814477d3674c60276b5079efa /src/port/win32fdatasync.c
parent623cc67347cc62eb676570c81abe5e1f63ecaa1e (diff)
downloadpostgresql-d2e150831af85fd30742f551a497db6639d91d0b.tar.gz
postgresql-d2e150831af85fd30742f551a497db6639d91d0b.zip
Remove configure probe for fdatasync.
fdatasync() is in SUSv2, and all targeted Unix systems have it. We have a replacement function for Windows. We retain the probe for the function declaration, which allows us to supply the mysteriously missing declaration for macOS, and also for Windows. No need to keep a HAVE_FDATASYNC macro around. Also rename src/port/fdatasync.c to win32fdatasync.c since it's only for Windows. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com Discussion: https://postgr.es/m/CA%2BhUKGJZJVO%3DiX%2Beb-PXi2_XS9ZRqnn_4URh0NUQOwt6-_51xQ%40mail.gmail.com
Diffstat (limited to 'src/port/win32fdatasync.c')
-rw-r--r--src/port/win32fdatasync.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/port/win32fdatasync.c b/src/port/win32fdatasync.c
new file mode 100644
index 00000000000..31d631c6962
--- /dev/null
+++ b/src/port/win32fdatasync.c
@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ *
+ * win32fdatasync.c
+ * Win32 fdatasync() replacement
+ *
+ *
+ * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
+ *
+ * src/port/win32fdatasync.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#define UMDF_USING_NTSTATUS
+
+#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;
+}