From 293913568e6a7a86fd1479e1cff8e2ecb58d6568 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 15:44:03 +0200 Subject: Adding upstream version 16.2. Signed-off-by: Daniel Baumann --- src/port/win32pwrite.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/port/win32pwrite.c (limited to 'src/port/win32pwrite.c') diff --git a/src/port/win32pwrite.c b/src/port/win32pwrite.c new file mode 100644 index 0000000..5dd1082 --- /dev/null +++ b/src/port/win32pwrite.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + * + * win32pwrite.c + * Implementation of pwrite(2) for Windows. + * + * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/port/win32pwrite.c + * + *------------------------------------------------------------------------- + */ + + +#include "c.h" + +#include + +ssize_t +pg_pwrite(int fd, const void *buf, size_t size, off_t offset) +{ + OVERLAPPED overlapped = {0}; + HANDLE handle; + DWORD result; + + handle = (HANDLE) _get_osfhandle(fd); + if (handle == INVALID_HANDLE_VALUE) + { + errno = EBADF; + return -1; + } + + /* Note that this changes the file position, despite not using it. */ + overlapped.Offset = offset; + if (!WriteFile(handle, buf, size, &result, &overlapped)) + { + _dosmaperr(GetLastError()); + return -1; + } + + return result; +} -- cgit v1.2.3