]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
mktime: DEBUG_MKTIME cleanup
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Nov 2018 21:59:33 +0000 (22:59 +0100)
committerAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Thu, 15 Nov 2018 21:59:33 +0000 (22:59 +0100)
The DEBUG_MKTIME code no longer works in glibc or in Gnulib.
And it’s no longer needed now that glibc and Gnulib both have
their own testing mechanisms for mktime.
* time/mktime.c (DEBUG_MKTIME): Remove.  All uses removed.

ChangeLog
time/mktime.c

index f4b6d06eae121886a4f6f301e079036bada23711..b24b6b002ef5c60889a192ec95077328b1733b3b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2018-11-15  Paul Eggert  <eggert@cs.ucla.edu>
 
+       mktime: DEBUG_MKTIME cleanup
+       The DEBUG_MKTIME code no longer works in glibc or in Gnulib.
+       And it’s no longer needed now that glibc and Gnulib both have
+       their own testing mechanisms for mktime.
+       * time/mktime.c (DEBUG_MKTIME): Remove.  All uses removed.
+
        mktime: fix non-EOVERFLOW errno handling
        [BZ#23789]
        mktime was not properly reporting failures when the underlying
index dc83985bbd30fe3773ce0de3ac68a384c17db284..8faa9bc93d331dd3c76ebda9d6389a26882ff03d 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-/* Define this to 1 to have a standalone program to test this implementation of
-   mktime.  */
-#ifndef DEBUG_MKTIME
-# define DEBUG_MKTIME 0
-#endif
-
 /* The following macros influence what gets defined when this file is compiled:
 
    Macro/expression            Which gnulib module    This compilation unit
    || NEED_MKTIME_WINDOWS
 
    NEED_MKTIME_INTERNAL        mktime-internal        mktime_internal
-
-   DEBUG_MKTIME                (defined manually)     my_mktime, main
  */
 
-#if !defined _LIBC && !DEBUG_MKTIME
+#ifndef _LIBC
 # include <libc-config.h>
 #endif
 
 #include <intprops.h>
 #include <verify.h>
 
-#if DEBUG_MKTIME
-# include <stdio.h>
-/* Make it work even if the system's libc has its own mktime routine.  */
-# undef mktime
-# define mktime my_mktime
-#endif /* DEBUG_MKTIME */
-
 #ifndef NEED_MKTIME_INTERNAL
 # define NEED_MKTIME_INTERNAL 0
 #endif
@@ -74,7 +59,7 @@
 # define NEED_MKTIME_WINDOWS 0
 #endif
 #ifndef NEED_MKTIME_WORKING
-# define NEED_MKTIME_WORKING DEBUG_MKTIME
+# define NEED_MKTIME_WORKING 0
 #endif
 
 #include "mktime-internal.h"
@@ -562,146 +547,3 @@ weak_alias (mktime, timelocal)
 libc_hidden_def (mktime)
 libc_hidden_weak (timelocal)
 #endif
-\f
-#if DEBUG_MKTIME
-
-static int
-not_equal_tm (const struct tm *a, const struct tm *b)
-{
-  return ((a->tm_sec ^ b->tm_sec)
-         | (a->tm_min ^ b->tm_min)
-         | (a->tm_hour ^ b->tm_hour)
-         | (a->tm_mday ^ b->tm_mday)
-         | (a->tm_mon ^ b->tm_mon)
-         | (a->tm_year ^ b->tm_year)
-         | (a->tm_yday ^ b->tm_yday)
-         | isdst_differ (a->tm_isdst, b->tm_isdst));
-}
-
-static void
-print_tm (const struct tm *tp)
-{
-  if (tp)
-    printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d",
-           tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday,
-           tp->tm_hour, tp->tm_min, tp->tm_sec,
-           tp->tm_yday, tp->tm_wday, tp->tm_isdst);
-  else
-    printf ("0");
-}
-
-static int
-check_result (time_t tk, struct tm tmk, time_t tl, const struct tm *lt)
-{
-  if (tk != tl || !lt || not_equal_tm (&tmk, lt))
-    {
-      printf ("mktime (");
-      print_tm (lt);
-      printf (")\nyields (");
-      print_tm (&tmk);
-      printf (") == %ld, should be %ld\n", (long int) tk, (long int) tl);
-      return 1;
-    }
-
-  return 0;
-}
-
-int
-main (int argc, char **argv)
-{
-  int status = 0;
-  struct tm tm, tmk, tml;
-  struct tm *lt;
-  time_t tk, tl, tl1;
-  char trailer;
-
-  /* Sanity check, plus call tzset.  */
-  tl = 0;
-  if (! localtime (&tl))
-    {
-      printf ("localtime (0) fails\n");
-      status = 1;
-    }
-
-  if ((argc == 3 || argc == 4)
-      && (sscanf (argv[1], "%d-%d-%d%c",
-                 &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer)
-         == 3)
-      && (sscanf (argv[2], "%d:%d:%d%c",
-                 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer)
-         == 3))
-    {
-      tm.tm_year -= TM_YEAR_BASE;
-      tm.tm_mon--;
-      tm.tm_isdst = argc == 3 ? -1 : atoi (argv[3]);
-      tmk = tm;
-      tl = mktime (&tmk);
-      lt = localtime_r (&tl, &tml);
-      printf ("mktime returns %ld == ", (long int) tl);
-      print_tm (&tmk);
-      printf ("\n");
-      status = check_result (tl, tmk, tl, lt);
-    }
-  else if (argc == 4 || (argc == 5 && strcmp (argv[4], "-") == 0))
-    {
-      time_t from = atol (argv[1]);
-      time_t by = atol (argv[2]);
-      time_t to = atol (argv[3]);
-
-      if (argc == 4)
-       for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
-         {
-           lt = localtime_r (&tl, &tml);
-           if (lt)
-             {
-               tmk = tml;
-               tk = mktime (&tmk);
-               status |= check_result (tk, tmk, tl, &tml);
-             }
-           else
-             {
-               printf ("localtime_r (%ld) yields 0\n", (long int) tl);
-               status = 1;
-             }
-           tl1 = tl + by;
-           if ((tl1 < tl) != (by < 0))
-             break;
-         }
-      else
-       for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
-         {
-           /* Null benchmark.  */
-           lt = localtime_r (&tl, &tml);
-           if (lt)
-             {
-               tmk = tml;
-               tk = tl;
-               status |= check_result (tk, tmk, tl, &tml);
-             }
-           else
-             {
-               printf ("localtime_r (%ld) yields 0\n", (long int) tl);
-               status = 1;
-             }
-           tl1 = tl + by;
-           if ((tl1 < tl) != (by < 0))
-             break;
-         }
-    }
-  else
-    printf ("Usage:\
-\t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\
-\t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\
-\t%s FROM BY TO - # Do not test those values (for benchmark).\n",
-           argv[0], argv[0], argv[0]);
-
-  return status;
-}
-
-#endif /* DEBUG_MKTIME */
-\f
-/*
-Local Variables:
-compile-command: "gcc -DDEBUG_MKTIME -I. -Wall -W -O2 -g mktime.c -o mktime"
-End:
-*/