Simplify gettimeofday() fallback logic.
authorAndres Freund <andres@anarazel.de>
Sat, 6 Aug 2022 15:34:56 +0000 (08:34 -0700)
committerAndres Freund <andres@anarazel.de>
Sat, 6 Aug 2022 15:34:56 +0000 (08:34 -0700)
There's no known supported system needing 1 argument gettimeofday()
support. The test for it was added a long time ago (92c6bf9775b). Remove.

Until now we tested whether a gettimeofday() fallback is needed when
targetting windows. Which lead to the odd result that HAVE_GETTIMEOFDAY only
being defined when targetting MinGW (which has gettimeofday() since at least
2007). As the fallback is specific to msvc, remove the configure code and
rename src/port/gettimeofday.c to src/port/win32gettimeofday.c.

While at it, also remove the definition of struct timezone, a forward
declaration of the struct is sufficient.

Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-By: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/20220806000311.ywx65iuchvj4qn2k@awork3.anarazel.de

config/c-library.m4
configure
configure.ac
src/include/pg_config.h.in
src/include/port.h
src/include/port/win32_port.h
src/port/win32gettimeofday.c [moved from src/port/gettimeofday.c with 98% similarity]
src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/Solution.pm

index 163ad5742d803d43bb3b2bfe4a8830dc6278e7bf..35fdc63afee85c0d7e55b9eb854362a8ba3b7fb5 100644 (file)
@@ -37,30 +37,6 @@ AC_DEFUN([PGAC_STRUCT_TIMEZONE],
 ])# PGAC_STRUCT_TIMEZONE
 
 
-# PGAC_FUNC_GETTIMEOFDAY_1ARG
-# ---------------------------
-# Check if gettimeofday() has only one arguments. (Normal is two.)
-# If so, define GETTIMEOFDAY_1ARG.
-AC_DEFUN([PGAC_FUNC_GETTIMEOFDAY_1ARG],
-[AC_CACHE_CHECK(whether gettimeofday takes only one argument,
-pgac_cv_func_gettimeofday_1arg,
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/time.h>],
-[struct timeval *tp;
-struct timezone *tzp;
-gettimeofday(tp,tzp);])],
-[pgac_cv_func_gettimeofday_1arg=no],
-[pgac_cv_func_gettimeofday_1arg=yes])])
-if test x"$pgac_cv_func_gettimeofday_1arg" = xyes ; then
-  AC_DEFINE(GETTIMEOFDAY_1ARG, 1,
-            [Define to 1 if gettimeofday() takes only 1 argument.])
-fi
-AH_VERBATIM(GETTIMEOFDAY_1ARG_,
-[@%:@ifdef GETTIMEOFDAY_1ARG
-@%:@ define gettimeofday(a,b) gettimeofday(a)
-@%:@endif])dnl
-])# PGAC_FUNC_GETTIMEOFDAY_1ARG
-
-
 # PGAC_FUNC_STRERROR_R_INT
 # ---------------------------
 # Check if strerror_r() returns int (POSIX) rather than char * (GNU libc).
index aa7f55b33a61c137da71c249fe40ced0ad8964a6..0e73edb9ffa499a950545521a5951aa378febc3b 100755 (executable)
--- a/configure
+++ b/configure
@@ -15945,39 +15945,6 @@ if test x"$pgac_cv_var_int_timezone" = xyes ; then
 $as_echo "#define HAVE_INT_TIMEZONE 1" >>confdefs.h
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether gettimeofday takes only one argument" >&5
-$as_echo_n "checking whether gettimeofday takes only one argument... " >&6; }
-if ${pgac_cv_func_gettimeofday_1arg+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/time.h>
-int
-main ()
-{
-struct timeval *tp;
-struct timezone *tzp;
-gettimeofday(tp,tzp);
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  pgac_cv_func_gettimeofday_1arg=no
-else
-  pgac_cv_func_gettimeofday_1arg=yes
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_func_gettimeofday_1arg" >&5
-$as_echo "$pgac_cv_func_gettimeofday_1arg" >&6; }
-if test x"$pgac_cv_func_gettimeofday_1arg" = xyes ; then
-
-$as_echo "#define GETTIMEOFDAY_1ARG 1" >>confdefs.h
-
-fi
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wcstombs_l declaration" >&5
 $as_echo_n "checking for wcstombs_l declaration... " >&6; }
 if ${pgac_cv_func_wcstombs_l+:} false; then :
@@ -16909,20 +16876,6 @@ _ACEOF
 fi
 done
 
-  ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday"
-if test "x$ac_cv_func_gettimeofday" = xyes; then :
-  $as_echo "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" gettimeofday.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
- ;;
-esac
-
-fi
-
-
   case " $LIBOBJS " in
   *" dirmod.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS dirmod.$ac_objext"
index 6a9463b5ae2abaed5b296fa1897fe8416a97978b..efd3be91cd47c4051e2e1f97e987784a4878689e 100644 (file)
@@ -1779,7 +1779,6 @@ fi
 ##
 
 PGAC_VAR_INT_TIMEZONE
-PGAC_FUNC_GETTIMEOFDAY_1ARG
 PGAC_FUNC_WCSTOMBS_L
 
 # Some versions of libedit contain strlcpy(), setproctitle(), and other
@@ -1925,7 +1924,6 @@ fi
 # Win32 (really MinGW) support
 if test "$PORTNAME" = "win32"; then
   AC_CHECK_FUNCS(_configthreadlocale)
-  AC_REPLACE_FUNCS(gettimeofday)
   AC_LIBOBJ(dirmod)
   AC_LIBOBJ(getrusage)
   AC_LIBOBJ(kill)
index b584788dc08c455738f2b7e596363d6a415bc12f..2d9a1cdc8ab06fafa3b4be280237fee55665143b 100644 (file)
    (--enable-thread-safety) */
 #undef ENABLE_THREAD_SAFETY
 
-/* Define to 1 if gettimeofday() takes only 1 argument. */
-#undef GETTIMEOFDAY_1ARG
-
-#ifdef GETTIMEOFDAY_1ARG
-# define gettimeofday(a,b) gettimeofday(a)
-#endif
-
 /* Define to 1 if you have the `append_history' function. */
 #undef HAVE_APPEND_HISTORY
 
 /* Define to 1 if you have the `getpeerucred' function. */
 #undef HAVE_GETPEERUCRED
 
-/* Define to 1 if you have the `gettimeofday' function. */
-#undef HAVE_GETTIMEOFDAY
-
 /* Define to 1 if you have the <gssapi/gssapi.h> header file. */
 #undef HAVE_GSSAPI_GSSAPI_H
 
index feb2ae840dd75e24bf866f441d1b025cf786d55a..ad76384fb195888c25cb7be2d8f467253dcb2b4a 100644 (file)
@@ -327,11 +327,6 @@ extern FILE *pgwin32_popen(const char *command, const char *type);
 #define popen(a,b) pgwin32_popen(a,b)
 #define pclose(a) _pclose(a)
 
-/* New versions of MingW have gettimeofday, old mingw and msvc don't */
-#ifndef HAVE_GETTIMEOFDAY
-/* Last parameter not used */
-extern int     gettimeofday(struct timeval *tp, struct timezone *tzp);
-#endif
 #else                                                  /* !WIN32 */
 
 /*
index a65996cce51e025a4905463d1a12758cef0fe16b..79451a00f96c46c726c00feb207a4c05f2e2deb6 100644 (file)
 #define SIGUSR1                                30
 #define SIGUSR2                                31
 
-/*
- * New versions of MinGW have gettimeofday() and also declare
- * struct timezone to support it.
- */
-#ifndef HAVE_GETTIMEOFDAY
-struct timezone
-{
-       int                     tz_minuteswest; /* Minutes west of GMT.  */
-       int                     tz_dsttime;             /* Nonzero if DST is ever in effect.  */
-};
+/* MinW has gettimeofday(), but MSVC doesn't */
+#ifdef _MSC_VER
+struct timezone;
+/* Last parameter not used */
+extern int     gettimeofday(struct timeval *tp, struct timezone *tzp);
 #endif
 
 /* for setitimer in backend/port/win32/timer.c */
similarity index 98%
rename from src/port/gettimeofday.c
rename to src/port/win32gettimeofday.c
index ee8fe8233784632e93ef56f72c7078a5b11fe588..0464548758333f7241901d7f42e0709fffaff71a 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * gettimeofday.c
+ * win32gettimeofday.c
  *       Win32 gettimeofday() replacement
  *
- * src/port/gettimeofday.c
+ * src/port/win32gettimeofday.c
  *
  * Copyright (c) 2003 SRA, Inc.
  * Copyright (c) 2003 SKC, Inc.
index 8d88e78f05141e198b09a23cbfedba302fe71d5c..bacc9207581faea124d8b3f89fd3092dee0dcad0 100644 (file)
@@ -101,7 +101,7 @@ sub mkvcbuild
        our @pgportfiles = qw(
          chklocale.c explicit_bzero.c
          getpeereid.c getrusage.c inet_aton.c
-         getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c
+         getaddrinfo.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
          preadv.c pwritev.c pg_bitutils.c
@@ -111,6 +111,7 @@ sub mkvcbuild
          win32dlopen.c
          win32env.c win32error.c
          win32fdatasync.c
+         win32gettimeofday.c
          win32link.c
          win32pread.c
          win32pwrite.c
index 9fe53bb036e38dba86e0880541668d513f1c43dc..4916a86f5cf41d084a0b3400ac18090ade26db3a 100644 (file)
@@ -220,7 +220,6 @@ sub GenerateFiles
                ENABLE_GSS                 => $self->{options}->{gss} ? 1 : undef,
                ENABLE_NLS                 => $self->{options}->{nls} ? 1 : undef,
                ENABLE_THREAD_SAFETY       => 1,
-               GETTIMEOFDAY_1ARG          => undef,
                HAVE_APPEND_HISTORY        => undef,
                HAVE_ASN1_STRING_GET0_DATA => undef,
                HAVE_ATOMICS               => 1,
@@ -267,7 +266,6 @@ sub GenerateFiles
                HAVE_GETOPT_LONG                            => undef,
                HAVE_GETPEEREID                             => undef,
                HAVE_GETPEERUCRED                           => undef,
-               HAVE_GETTIMEOFDAY                           => undef,
                HAVE_GSSAPI_GSSAPI_H                        => undef,
                HAVE_GSSAPI_H                               => undef,
                HAVE_HMAC_CTX_FREE                          => undef,