From 1c5a70717e6d20139d77fe1cba1f6c82da4d079e Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Sun, 24 Jul 2022 01:12:31 +1200
Subject: [PATCH 06/13] Remove configure probe for symlink, and dead code.

symlink() is in SUSv2 and all targeted Unix systems have it.  Windows
doesn't have it, but we have replacement code that doesn't need a
configure probe.
---
 configure                             |  5 +----
 configure.ac                          |  3 ---
 src/backend/commands/tablespace.c     | 13 -------------
 src/bin/initdb/initdb.c               |  4 ----
 src/bin/pg_basebackup/pg_basebackup.c |  4 ----
 src/include/pg_config.h.in            |  3 ---
 src/timezone/zic.c                    | 10 ----------
 src/tools/msvc/Solution.pm            |  1 -
 8 files changed, 1 insertion(+), 42 deletions(-)

diff --git a/configure b/configure
index 6e10773263..b18198bf5f 100755
--- a/configure
+++ b/configure
@@ -16039,7 +16039,7 @@ fi
 LIBS_including_readline="$LIBS"
 LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
 
-for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pthread_is_threaded_np readv setproctitle setproctitle_fast strchrnul strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev
+for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pthread_is_threaded_np readv setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l writev
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -17107,9 +17107,6 @@ esac
  ;;
 esac
 
-
-$as_echo "#define HAVE_SYMLINK 1" >>confdefs.h
-
   ac_fn_c_check_type "$LINENO" "MINIDUMP_TYPE" "ac_cv_type_MINIDUMP_TYPE" "
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
diff --git a/configure.ac b/configure.ac
index b4015aebb4..a89992caf6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1810,7 +1810,6 @@ AC_CHECK_FUNCS(m4_normalize([
 	setproctitle_fast
 	strchrnul
 	strsignal
-	symlink
 	syncfs
 	sync_file_range
 	uselocale
@@ -1964,8 +1963,6 @@ if test "$PORTNAME" = "win32"; then
   AC_LIBOBJ(win32security)
   AC_LIBOBJ(win32setlocale)
   AC_LIBOBJ(win32stat)
-  AC_DEFINE([HAVE_SYMLINK], 1,
-            [Define to 1 if you have the `symlink' function.])
   AC_CHECK_TYPES(MINIDUMP_TYPE, [pgac_minidump_type=yes], [pgac_minidump_type=no], [
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index cb7d46089a..7ab6ec6d68 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -235,7 +235,6 @@ TablespaceCreateDbspace(Oid spcOid, Oid dbOid, bool isRedo)
 Oid
 CreateTableSpace(CreateTableSpaceStmt *stmt)
 {
-#ifdef HAVE_SYMLINK
 	Relation	rel;
 	Datum		values[Natts_pg_tablespace];
 	bool		nulls[Natts_pg_tablespace] = {0};
@@ -413,12 +412,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
 	table_close(rel, NoLock);
 
 	return tablespaceoid;
-#else							/* !HAVE_SYMLINK */
-	ereport(ERROR,
-			(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-			 errmsg("tablespaces are not supported on this platform")));
-	return InvalidOid;			/* keep compiler quiet */
-#endif							/* HAVE_SYMLINK */
 }
 
 /*
@@ -429,7 +422,6 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
 void
 DropTableSpace(DropTableSpaceStmt *stmt)
 {
-#ifdef HAVE_SYMLINK
 	char	   *tablespacename = stmt->tablespacename;
 	TableScanDesc scandesc;
 	Relation	rel;
@@ -595,11 +587,6 @@ DropTableSpace(DropTableSpaceStmt *stmt)
 
 	/* We keep the lock on pg_tablespace until commit */
 	table_close(rel, NoLock);
-#else							/* !HAVE_SYMLINK */
-	ereport(ERROR,
-			(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-			 errmsg("tablespaces are not supported on this platform")));
-#endif							/* HAVE_SYMLINK */
 }
 
 
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 85fc95503a..3e607b824f 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -2646,13 +2646,9 @@ create_xlog_or_symlink(void)
 				pg_fatal("could not access directory \"%s\": %m", xlog_dir);
 		}
 
-#ifdef HAVE_SYMLINK
 		if (symlink(xlog_dir, subdirloc) != 0)
 			pg_fatal("could not create symbolic link \"%s\": %m",
 					 subdirloc);
-#else
-		pg_fatal("symlinks are not supported on this platform");
-#endif
 	}
 	else
 	{
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 1a877ba54e..8694b05e68 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -2763,12 +2763,8 @@ main(int argc, char **argv)
 						   PQserverVersion(conn) < MINIMUM_VERSION_FOR_PG_WAL ?
 						   "pg_xlog" : "pg_wal");
 
-#ifdef HAVE_SYMLINK
 		if (symlink(xlog_dir, linkloc) != 0)
 			pg_fatal("could not create symbolic link \"%s\": %m", linkloc);
-#else
-		pg_fatal("symlinks are not supported on this platform");
-#endif
 		free(linkloc);
 	}
 
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 9fc0298f7d..61634347d5 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -561,9 +561,6 @@
 /* Define to 1 if `tm_zone' is a member of `struct tm'. */
 #undef HAVE_STRUCT_TM_TM_ZONE
 
-/* Define to 1 if you have the `symlink' function. */
-#undef HAVE_SYMLINK
-
 /* Define to 1 if you have the `syncfs' function. */
 #undef HAVE_SYNCFS
 
diff --git a/src/timezone/zic.c b/src/timezone/zic.c
index 0ea6ead2db..2c55a009a8 100644
--- a/src/timezone/zic.c
+++ b/src/timezone/zic.c
@@ -944,7 +944,6 @@ namecheck(const char *name)
  * is relative to the global variable DIRECTORY.  TO can be either
  * relative or absolute.
  */
-#ifdef HAVE_SYMLINK
 static char *
 relname(char const *target, char const *linkname)
 {
@@ -986,7 +985,6 @@ relname(char const *target, char const *linkname)
 	}
 	return result;
 }
-#endif							/* HAVE_SYMLINK */
 
 /* Hard link FROM to TO, following any symbolic links.
    Return 0 if successful, an error number otherwise.  */
@@ -1038,7 +1036,6 @@ dolink(char const *target, char const *linkname, bool staysymlink)
 	}
 	if (link_errno != 0)
 	{
-#ifdef HAVE_SYMLINK
 		bool		absolute = *target == '/';
 		char	   *linkalloc = absolute ? NULL : relname(target, linkname);
 		char const *contents = absolute ? target : linkalloc;
@@ -1059,7 +1056,6 @@ dolink(char const *target, char const *linkname, bool staysymlink)
 						strerror(link_errno));
 		}
 		else
-#endif							/* HAVE_SYMLINK */
 		{
 			FILE	   *fp,
 					   *tp;
@@ -1090,11 +1086,9 @@ dolink(char const *target, char const *linkname, bool staysymlink)
 			if (link_errno != ENOTSUP)
 				warning(_("copy used because hard link failed: %s"),
 						strerror(link_errno));
-#ifdef HAVE_SYMLINK
 			else if (symlink_errno != ENOTSUP)
 				warning(_("copy used because symbolic link failed: %s"),
 						strerror(symlink_errno));
-#endif
 		}
 	}
 }
@@ -1128,13 +1122,9 @@ itsdir(char const *name)
 static bool
 itssymlink(char const *name)
 {
-#ifdef HAVE_SYMLINK
 	char		c;
 
 	return 0 <= readlink(name, &c, 1);
-#else
-	return false;
-#endif
 }
 
 /*
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index f9aec9494e..5030f63e9a 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -381,7 +381,6 @@ sub GenerateFiles
 		HAVE_STRUCT_SOCKADDR_UN                  => undef,
 		HAVE_STRUCT_TM_TM_ZONE                   => undef,
 		HAVE_SYNC_FILE_RANGE                     => undef,
-		HAVE_SYMLINK                             => 1,
 		HAVE_SYNCFS                              => undef,
 		HAVE_SYSLOG                              => undef,
 		HAVE_SYS_EPOLL_H                         => undef,
-- 
2.30.2

