From 5963c9a154bd5590a7ea48826d9bd72c9324e071 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 5 Aug 2022 09:36:50 +1200 Subject: 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. Since only Windows needs it, rename src/port/link.c to win32link.c like other similar things. There is no need for a vestigial HAVE_LINK macro, because we expect all Unix and, with our replacement function, Windows systems to have it, so we didn't have any tests around link() usage. Reviewed-by: Tom Lane Reviewed-by: Andres Freund Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com --- src/include/pg_config.h.in | 3 --- src/include/port.h | 3 ++- src/port/link.c | 35 ----------------------------------- src/port/win32link.c | 31 +++++++++++++++++++++++++++++++ src/tools/msvc/Mkvcbuild.pm | 6 ++++-- src/tools/msvc/Solution.pm | 1 - 6 files changed, 37 insertions(+), 42 deletions(-) delete mode 100644 src/port/link.c create mode 100644 src/port/win32link.c (limited to 'src') diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 15e01efa068..beb42549c16 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -334,9 +334,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 7dad6caa639..a219a8b8689 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 +/* src/port/win32link.c */ extern int link(const char *src, const char *dst); #endif diff --git a/src/port/link.c b/src/port/link.c deleted file mode 100644 index 1e0ccd4648a..00000000000 --- a/src/port/link.c +++ /dev/null @@ -1,35 +0,0 @@ -/*------------------------------------------------------------------------- - * - * link.c - * - * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * src/port/link.c - * - *------------------------------------------------------------------------- - */ - -#include "c.h" - -#ifdef WIN32 - -int -link(const char *src, const char *dst) -{ - /* - * CreateHardLinkA returns zero for failure - * https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka - */ - if (CreateHardLinkA(dst, src, NULL) == 0) - { - _dosmaperr(GetLastError()); - return -1; - } - else - return 0; -} - -#endif diff --git a/src/port/win32link.c b/src/port/win32link.c new file mode 100644 index 00000000000..06584790465 --- /dev/null +++ b/src/port/win32link.c @@ -0,0 +1,31 @@ +/*------------------------------------------------------------------------- + * + * win32link.c + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/port/win32link.c + * + *------------------------------------------------------------------------- + */ + +#include "c.h" + +int +link(const char *src, const char *dst) +{ + /* + * CreateHardLinkA returns zero for failure + * https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka + */ + if (CreateHardLinkA(dst, src, NULL) == 0) + { + _dosmaperr(GetLastError()); + return -1; + } + else + return 0; +} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 266f98e2ed4..1ffe6e66d5a 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -103,13 +103,15 @@ sub mkvcbuild getpeereid.c getrusage.c inet_aton.c getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c - dirent.c getopt.c getopt_long.c link.c + dirent.c getopt.c getopt_long.c pread.c preadv.c pwrite.c pwritev.c pg_bitutils.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c pqsignal.c mkdtemp.c qsort.c qsort_arg.c bsearch_arg.c quotes.c system.c strerror.c tar.c win32dlopen.c - win32env.c win32error.c win32ntdll.c + win32env.c win32error.c + win32link.c + win32ntdll.c win32security.c win32setlocale.c win32stat.c); push(@pgportfiles, 'strtof.c') if ($vsVersion < '14.00'); diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 71db5f60f8a..7806ad67d08 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -306,7 +306,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, -- cgit v1.2.3