From cf112c122060568aa06efe4e6e6fb9b2dd4f1090 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 5 Aug 2022 09:42:31 +1200 Subject: 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 Reviewed-by: Greg Stark Reviewed-by: Robert Haas Reviewed-by: Andres Freund Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com --- src/include/access/xlogreader.h | 4 ++-- src/include/pg_config.h.in | 6 ------ src/include/port.h | 19 ------------------- src/include/port/win32_port.h | 6 ++++++ 4 files changed, 8 insertions(+), 27 deletions(-) (limited to 'src/include') diff --git a/src/include/access/xlogreader.h b/src/include/access/xlogreader.h index 5395f155aa1..87ff00feb72 100644 --- a/src/include/access/xlogreader.h +++ b/src/include/access/xlogreader.h @@ -375,11 +375,11 @@ extern bool XLogReaderValidatePageHeader(XLogReaderState *state, /* * Error information from WALRead that both backend and frontend caller can - * process. Currently only errors from pg_pread can be reported. + * process. Currently only errors from pread can be reported. */ typedef struct WALReadError { - int wre_errno; /* errno set by the last pg_pread() */ + int wre_errno; /* errno set by the last pread() */ int wre_off; /* Offset we tried to read from. */ int wre_req; /* Bytes requested to be read. */ int wre_read; /* Bytes read by the last read(). */ diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index b6ee575681c..4d61ecd9142 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -388,9 +388,6 @@ /* Define to 1 if you have the `ppoll' function. */ #undef HAVE_PPOLL -/* Define to 1 if you have the `pread' function. */ -#undef HAVE_PREAD - /* Define to 1 if the PS_STRINGS thing exists. */ #undef HAVE_PS_STRINGS @@ -406,9 +403,6 @@ /* Have PTHREAD_PRIO_INHERIT. */ #undef HAVE_PTHREAD_PRIO_INHERIT -/* Define to 1 if you have the `pwrite' function. */ -#undef HAVE_PWRITE - /* Define to 1 if you have the header file. */ #undef HAVE_READLINE_H diff --git a/src/include/port.h b/src/include/port.h index 85c9b38f4ee..14b640fe33e 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -417,25 +417,6 @@ extern char *mkdtemp(char *path); extern int inet_aton(const char *cp, struct in_addr *addr); #endif -/* - * Windows and older Unix don't have pread(2) and pwrite(2). We have - * replacement functions, but they have slightly different semantics so we'll - * use a name with a pg_ prefix to avoid confusion. - */ -#ifdef HAVE_PREAD -#define pg_pread pread -#else -extern ssize_t pg_pread(int fd, void *buf, size_t nbyte, off_t offset); -#endif - -#ifdef HAVE_PWRITE -#define pg_pwrite pwrite -#else -extern ssize_t pg_pwrite(int fd, const void *buf, size_t nbyte, off_t offset); -#endif - -/* For pg_pwritev() and pg_preadv(), see port/pg_iovec.h. */ - #if !HAVE_DECL_STRLCAT extern size_t strlcat(char *dst, const char *src, size_t siz); #endif diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h index a48eed53eb7..336e11b3ba4 100644 --- a/src/include/port/win32_port.h +++ b/src/include/port/win32_port.h @@ -562,4 +562,10 @@ typedef unsigned short mode_t; #define HAVE_BUGGY_STRTOF 1 #endif +/* in port/win32pread.c */ +extern ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset); + +/* in port/win32pwrite.c */ +extern ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset); + #endif /* PG_WIN32_PORT_H */ -- cgit v1.2.3