From 85584131bc1fcde2e54984f853b79b23a5331a43 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 11 Aug 2022 14:19:38 +1200
Subject: [PATCH 1/7] Remove configure probe for sys/uio.h.

<sys/uio.h> is in SUSv2, and all targeted Unix system have it, so we
might as well drop the probe (in fact we never really needed this one,
as even HP-UX 10.20 had it).  It's where struct iovec is defined, and as
a common extension, it's also where non-standard preadv() and pwritev()
are declared on systems that have it.

It's a little confusing so let's spell what our pg_iovec.h header does
for the OSes in the build farm today:

Windows: defines our own struct and declares our own functions
Solaris: includes sys/uio.h for the struct and declares our own functions
Every other targeted Unix: includes sys/uio.h for the struct and the functions
---
 configure                   |  2 +-
 configure.ac                |  1 -
 src/include/pg_config.h.in  |  3 ---
 src/include/port/pg_iovec.h | 20 ++++++++------------
 src/tools/msvc/Solution.pm  |  1 -
 5 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/configure b/configure
index cf2c4b85fe..ef5334a12d 100755
--- a/configure
+++ b/configure
@@ -13874,7 +13874,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
 fi
 
 
-for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h net/if.h netinet/tcp.h sys/epoll.h sys/event.h sys/ipc.h sys/personality.h sys/prctl.h sys/procctl.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/signalfd.h sys/sockio.h sys/ucred.h sys/uio.h sys/un.h termios.h ucred.h
+for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h net/if.h netinet/tcp.h sys/epoll.h sys/event.h sys/ipc.h sys/personality.h sys/prctl.h sys/procctl.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/signalfd.h sys/sockio.h sys/ucred.h sys/un.h termios.h ucred.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/configure.ac b/configure.ac
index b5798bcb0a..c1b75e0f34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1467,7 +1467,6 @@ AC_CHECK_HEADERS(m4_normalize([
 	sys/signalfd.h
 	sys/sockio.h
 	sys/ucred.h
-	sys/uio.h
 	sys/un.h
 	termios.h
 	ucred.h
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index fc5ad5fd65..ed6185343e 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -538,9 +538,6 @@
 /* Define to 1 if you have the <sys/ucred.h> header file. */
 #undef HAVE_SYS_UCRED_H
 
-/* Define to 1 if you have the <sys/uio.h> header file. */
-#undef HAVE_SYS_UIO_H
-
 /* Define to 1 if you have the <sys/un.h> header file. */
 #undef HAVE_SYS_UN_H
 
diff --git a/src/include/port/pg_iovec.h b/src/include/port/pg_iovec.h
index f0a50c0e01..ecdddba7fc 100644
--- a/src/include/port/pg_iovec.h
+++ b/src/include/port/pg_iovec.h
@@ -13,27 +13,23 @@
 #ifndef PG_IOVEC_H
 #define PG_IOVEC_H
 
-#include <limits.h>
+#ifndef WIN32
 
-#ifdef HAVE_SYS_UIO_H
+#include <limits.h>
 #include <sys/uio.h>
-#endif
 
-/* If <sys/uio.h> is missing, define our own POSIX-compatible iovec struct. */
-#ifndef HAVE_SYS_UIO_H
+#else
+
+/* POSIX requires at least 16 as a maximum iovcnt. */
+#define IOV_MAX 16
+
+/* Define our own POSIX-compatible iovec struct. */
 struct iovec
 {
 	void	   *iov_base;
 	size_t		iov_len;
 };
-#endif
 
-/*
- * If <limits.h> didn't define IOV_MAX, define our own.  POSIX requires at
- * least 16.
- */
-#ifndef IOV_MAX
-#define IOV_MAX 16
 #endif
 
 /* Define a reasonable maximum that is safe to use on the stack. */
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index cc82668457..741998a103 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -375,7 +375,6 @@ sub GenerateFiles
 		HAVE_SYS_STAT_H                          => 1,
 		HAVE_SYS_TYPES_H                         => 1,
 		HAVE_SYS_UCRED_H                         => undef,
-		HAVE_SYS_UIO_H                           => undef,
 		HAVE_SYS_UN_H                            => undef,
 		HAVE_TERMIOS_H                           => undef,
 		HAVE_TYPEOF                              => undef,
-- 
2.32.1 (Apple Git-133)

