summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorThomas Munro2022-08-04 21:42:31 +0000
committerThomas Munro2022-08-04 21:49:21 +0000
commitcf112c122060568aa06efe4e6e6fb9b2dd4f1090 (patch)
tree099d16d2064108f43c06d70ab5178a38d8554106 /src/port
parent71f5dc6dfb3de50de28ddde53793540c2fa98b1f (diff)
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
Diffstat (limited to 'src/port')
-rw-r--r--src/port/preadv.c4
-rw-r--r--src/port/pwritev.c4
-rw-r--r--src/port/win32pread.c (renamed from src/port/pread.c)22
-rw-r--r--src/port/win32pwrite.c (renamed from src/port/pwrite.c)22
4 files changed, 12 insertions, 40 deletions
diff --git a/src/port/preadv.c b/src/port/preadv.c
index d12e5a122bb..aa7537503fb 100644
--- a/src/port/preadv.c
+++ b/src/port/preadv.c
@@ -30,7 +30,7 @@ pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
{
#ifdef HAVE_READV
if (iovcnt == 1)
- return pg_pread(fd, iov[0].iov_base, iov[0].iov_len, offset);
+ return pread(fd, iov[0].iov_base, iov[0].iov_len, offset);
if (lseek(fd, offset, SEEK_SET) < 0)
return -1;
return readv(fd, iov, iovcnt);
@@ -40,7 +40,7 @@ pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
for (int i = 0; i < iovcnt; ++i)
{
- part = pg_pread(fd, iov[i].iov_base, iov[i].iov_len, offset);
+ part = pread(fd, iov[i].iov_base, iov[i].iov_len, offset);
if (part < 0)
{
if (i == 0)
diff --git a/src/port/pwritev.c b/src/port/pwritev.c
index 0bdd69fffc4..cb7421381e4 100644
--- a/src/port/pwritev.c
+++ b/src/port/pwritev.c
@@ -30,7 +30,7 @@ pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
{
#ifdef HAVE_WRITEV
if (iovcnt == 1)
- return pg_pwrite(fd, iov[0].iov_base, iov[0].iov_len, offset);
+ return pwrite(fd, iov[0].iov_base, iov[0].iov_len, offset);
if (lseek(fd, offset, SEEK_SET) < 0)
return -1;
return writev(fd, iov, iovcnt);
@@ -40,7 +40,7 @@ pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
for (int i = 0; i < iovcnt; ++i)
{
- part = pg_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
+ part = pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
if (part < 0)
{
if (i == 0)
diff --git a/src/port/pread.c b/src/port/win32pread.c
index 491605926f2..7058c3460b5 100644
--- a/src/port/pread.c
+++ b/src/port/win32pread.c
@@ -1,15 +1,12 @@
/*-------------------------------------------------------------------------
*
- * pread.c
- * Implementation of pread(2) for platforms that lack one.
+ * win32pread.c
+ * Implementation of pread(2) for Windows.
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * src/port/pread.c
- *
- * Note that this implementation changes the current file position, unlike
- * the POSIX function, so we use the name pg_pread().
+ * src/port/win32pread.c
*
*-------------------------------------------------------------------------
*/
@@ -17,16 +14,11 @@
#include "postgres.h"
-#ifdef WIN32
#include <windows.h>
-#else
-#include <unistd.h>
-#endif
ssize_t
-pg_pread(int fd, void *buf, size_t size, off_t offset)
+pread(int fd, void *buf, size_t size, off_t offset)
{
-#ifdef WIN32
OVERLAPPED overlapped = {0};
HANDLE handle;
DWORD result;
@@ -49,10 +41,4 @@ pg_pread(int fd, void *buf, size_t size, off_t offset)
}
return result;
-#else
- if (lseek(fd, offset, SEEK_SET) < 0)
- return -1;
-
- return read(fd, buf, size);
-#endif
}
diff --git a/src/port/pwrite.c b/src/port/win32pwrite.c
index eeaffacc48a..455cec4a747 100644
--- a/src/port/pwrite.c
+++ b/src/port/win32pwrite.c
@@ -1,15 +1,12 @@
/*-------------------------------------------------------------------------
*
- * pwrite.c
- * Implementation of pwrite(2) for platforms that lack one.
+ * win32pwrite.c
+ * Implementation of pwrite(2) for Windows.
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * src/port/pwrite.c
- *
- * Note that this implementation changes the current file position, unlike
- * the POSIX function, so we use the name pg_pwrite().
+ * src/port/win32pwrite.c
*
*-------------------------------------------------------------------------
*/
@@ -17,16 +14,11 @@
#include "postgres.h"
-#ifdef WIN32
#include <windows.h>
-#else
-#include <unistd.h>
-#endif
ssize_t
-pg_pwrite(int fd, const void *buf, size_t size, off_t offset)
+pwrite(int fd, const void *buf, size_t size, off_t offset)
{
-#ifdef WIN32
OVERLAPPED overlapped = {0};
HANDLE handle;
DWORD result;
@@ -46,10 +38,4 @@ pg_pwrite(int fd, const void *buf, size_t size, off_t offset)
}
return result;
-#else
- if (lseek(fd, offset, SEEK_SET) < 0)
- return -1;
-
- return write(fd, buf, size);
-#endif
}