Fix a compiler warning in initStringInfo().
[pgsql.git] / src / port / win32pread.c
blob32d56c462ecb9bc8c9bb2484f1f42b3cb4066459
1 /*-------------------------------------------------------------------------
3 * win32pread.c
4 * Implementation of pread(2) for Windows.
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * IDENTIFICATION
9 * src/port/win32pread.c
11 *-------------------------------------------------------------------------
15 #include "c.h"
17 #include <windows.h>
19 ssize_t
20 pg_pread(int fd, void *buf, size_t size, off_t offset)
22 OVERLAPPED overlapped = {0};
23 HANDLE handle;
24 DWORD result;
26 handle = (HANDLE) _get_osfhandle(fd);
27 if (handle == INVALID_HANDLE_VALUE)
29 errno = EBADF;
30 return -1;
33 /* Avoid overflowing DWORD. */
34 size = Min(size, 1024 * 1024 * 1024);
36 /* Note that this changes the file position, despite not using it. */
37 overlapped.Offset = offset;
38 if (!ReadFile(handle, buf, size, &result, &overlapped))
40 if (GetLastError() == ERROR_HANDLE_EOF)
41 return 0;
43 _dosmaperr(GetLastError());
44 return -1;
47 return result;