Include stat-time.h, and use its functions instead of the obsolete
[platform/upstream/coreutils.git] / src / date.c
index 58fe96e..af9485b 100644 (file)
@@ -33,8 +33,8 @@
 #include "inttostr.h"
 #include "posixtm.h"
 #include "quote.h"
-#include "strftime.h"
-#include "xanstrftime.h"
+#include "stat-time.h"
+#include "fprintftime.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "date"
@@ -494,10 +494,9 @@ main (int argc, char **argv)
          /* (option_specified_date || set_date) */
          if (reference != NULL)
            {
-             if (stat (reference, &refstats))
+             if (stat (reference, &refstats) != 0)
                error (EXIT_FAILURE, errno, "%s", reference);
-             when.tv_sec = refstats.st_mtime;
-             when.tv_nsec = TIMESPEC_NS (refstats.st_mtim);
+             when = get_stat_mtime (&refstats);
            }
          else
            {
@@ -549,16 +548,12 @@ show_date (const char *format, struct timespec when)
     }
 
   {
-    char *out;
-
     if (format == rfc_2822_format)
       setlocale (LC_TIME, "C");
-    out = xanstrftime (format, tm, 0, when.tv_nsec);
+    fprintftime (stdout, format, tm, 0, when.tv_nsec);
+    fputc ('\n', stdout);
     if (format == rfc_2822_format)
       setlocale (LC_TIME, "");
-
-    puts (out);
-    free (out);
   }
   return true;
 }