1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-09 22:41:56 +03:00

Remove dead pread and pwrite replacement code.

pread() and pwrite() are in SUSv2, and all targeted Unix systems have
them.

Previously, we defined pg_pread and pg_pwrite to emulate these function
with lseek() on old Unixen.  The names with a pg_ prefix were a reminder
of a portability hazard: they might change the current file position.
That hazard is gone, so we can drop the prefixes.

Since the remaining replacement code is Windows-only, move it into
src/port/win32p{read,write}.c, and move the declarations into
src/include/port/win32_port.h.

No need for vestigial HAVE_PREAD, HAVE_PWRITE macros as they were only
used for declarations in port.h which have now moved into win32_port.h.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Greg Stark <stark@mit.edu>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com
This commit is contained in:
Thomas Munro
2022-08-05 09:42:31 +12:00
parent 71f5dc6dfb
commit cf112c1220
23 changed files with 76 additions and 137 deletions

44
src/port/win32pread.c Normal file
View File

@ -0,0 +1,44 @@
/*-------------------------------------------------------------------------
*
* win32pread.c
* Implementation of pread(2) for Windows.
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/port/win32pread.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include <windows.h>
ssize_t
pread(int fd, 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;
}
overlapped.Offset = offset;
if (!ReadFile(handle, buf, size, &result, &overlapped))
{
if (GetLastError() == ERROR_HANDLE_EOF)
return 0;
_dosmaperr(GetLastError());
return -1;
}
return result;
}