From 66dc6f1601da55342702b604fc0e90adbdc99d83 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Sun, 24 Jul 2022 01:19:05 +1200
Subject: [PATCH 07/13] Remove configure probe for link.

link() is in SUSv2 and all targeted Unix systems have it.  We have
replacement code for Windows that doesn't require a configure probe.
---
 configure                  | 19 ++++++-------------
 configure.ac               |  2 +-
 src/include/pg_config.h.in |  3 ---
 src/include/port.h         |  3 ++-
 src/port/link.c            |  4 ----
 src/tools/msvc/Solution.pm |  1 -
 6 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/configure b/configure
index b18198bf5f..85efc8984d 100755
--- a/configure
+++ b/configure
@@ -16739,19 +16739,6 @@ esac
 
 fi
 
-ac_fn_c_check_func "$LINENO" "link" "ac_cv_func_link"
-if test "x$ac_cv_func_link" = xyes; then :
-  $as_echo "#define HAVE_LINK 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" link.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS link.$ac_objext"
- ;;
-esac
-
-fi
-
 ac_fn_c_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
 if test "x$ac_cv_func_mkdtemp" = xyes; then :
   $as_echo "#define HAVE_MKDTEMP 1" >>confdefs.h
@@ -17059,6 +17046,12 @@ esac
  ;;
 esac
 
+  case " $LIBOBJS " in
+  *" link.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS link.$ac_objext"
+ ;;
+esac
+
   case " $LIBOBJS " in
   *" open.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS open.$ac_objext"
diff --git a/configure.ac b/configure.ac
index a89992caf6..0fb7396669 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1879,7 +1879,6 @@ AC_REPLACE_FUNCS(m4_normalize([
 	getopt
 	getpeereid
 	inet_aton
-	link
 	mkdtemp
 	pread
 	pwrite
@@ -1955,6 +1954,7 @@ if test "$PORTNAME" = "win32"; then
   AC_LIBOBJ(fdatasync)
   AC_LIBOBJ(getrusage)
   AC_LIBOBJ(kill)
+  AC_LIBOBJ(link)
   AC_LIBOBJ(open)
   AC_LIBOBJ(system)
   AC_LIBOBJ(win32env)
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 61634347d5..ba9d702101 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -342,9 +342,6 @@
 /* Define to 1 if you have the `zstd' library (-lzstd). */
 #undef HAVE_LIBZSTD
 
-/* Define to 1 if you have the `link' function. */
-#undef HAVE_LINK
-
 /* Define to 1 if the system has the type `locale_t'. */
 #undef HAVE_LOCALE_T
 
diff --git a/src/include/port.h b/src/include/port.h
index 4532608bb3..666f6b04f9 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -402,7 +402,8 @@ extern float pg_strtof(const char *nptr, char **endptr);
 #define strtof(a,b) (pg_strtof((a),(b)))
 #endif
 
-#ifndef HAVE_LINK
+#ifdef WIN32
+/* replacement in src/port/link.c */
 extern int	link(const char *src, const char *dst);
 #endif
 
diff --git a/src/port/link.c b/src/port/link.c
index 1e0ccd4648..45517280db 100644
--- a/src/port/link.c
+++ b/src/port/link.c
@@ -14,8 +14,6 @@
 
 #include "c.h"
 
-#ifdef WIN32
-
 int
 link(const char *src, const char *dst)
 {
@@ -31,5 +29,3 @@ link(const char *src, const char *dst)
 	else
 		return 0;
 }
-
-#endif
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 5030f63e9a..d904f42d53 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -308,7 +308,6 @@ sub GenerateFiles
 		HAVE_LIBXSLT                                => undef,
 		HAVE_LIBZ                   => $self->{options}->{zlib} ? 1 : undef,
 		HAVE_LIBZSTD                => undef,
-		HAVE_LINK                   => undef,
 		HAVE_LOCALE_T               => 1,
 		HAVE_LONG_INT_64            => undef,
 		HAVE_LONG_LONG_INT_64       => 1,
-- 
2.30.2

