1 /*-------------------------------------------------------------------------
4 * Implementation of pwrite(2) for platforms that lack one.
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
11 * Note that this implementation changes the current file position, unlike
12 * the POSIX function, so we use the name pg_pwrite().
14 *-------------------------------------------------------------------------
27 pg_pwrite(int fd
, const void *buf
, size_t size
, off_t offset
)
30 OVERLAPPED overlapped
= {0};
34 handle
= (HANDLE
) _get_osfhandle(fd
);
35 if (handle
== INVALID_HANDLE_VALUE
)
41 overlapped
.Offset
= offset
;
42 if (!WriteFile(handle
, buf
, size
, &result
, &overlapped
))
44 _dosmaperr(GetLastError());
50 if (lseek(fd
, offset
, SEEK_SET
) < 0)
53 return write(fd
, buf
, size
);