OSDN Git Service

Backport from mainline
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / date_and_time.c
index 714df14..3c38636 100644 (file)
@@ -31,29 +31,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "time_1.h"
 
-#ifndef abs
-#define abs(x) ((x)>=0 ? (x) : -(x))
-#endif
-
-
-/* If the re-entrant versions of localtime and gmtime are not
-   available, provide fallback implementations.  On some targets where
-   the _r versions are not available, localtime and gmtime use
-   thread-local storage so they are threadsafe.  */
 
-#ifndef HAVE_LOCALTIME_R
-/* If _POSIX is defined localtime_r gets defined by mingw-w64 headers.  */
-#ifdef localtime_r
-#undef localtime_r
-#endif
-
-static struct tm *
-localtime_r (const time_t * timep, struct tm * result)
-{
-  *result = *localtime (timep);
-  return result;
-}
-#endif
+/* If the re-entrant version of gmtime is not available, provide a
+   fallback implementation.  On some targets where the _r version is
+   not available, gmtime uses thread-local storage so it's
+   threadsafe.  */
 
 #ifndef HAVE_GMTIME_R
 /* If _POSIX is defined gmtime_r gets defined by mingw-w64 headers.  */
@@ -157,16 +139,15 @@ date_and_time (char *__date, char *__time, char *__zone,
   char zone[ZONE_LEN + 1];
   GFC_INTEGER_4 values[VALUES_SIZE];
 
-#ifndef HAVE_NO_DATE_TIME
   time_t lt;
   struct tm local_time;
   struct tm UTC_time;
 
-  long nanosecs;
+  long usecs;
 
-  if (!gf_gettime(GF_CLOCK_REALTIME, &lt, &nanosecs))
+  if (!gf_gettime (&lt, &usecs))
     {
-      values[7] = nanosecs / 1000000;
+      values[7] = usecs / 1000;
 
       localtime_r (&lt, &local_time);
       gmtime_r (&lt, &UTC_time);
@@ -182,7 +163,6 @@ date_and_time (char *__date, char *__time, char *__zone,
       values[5] = local_time.tm_min;
       values[6] = local_time.tm_sec;
 
-#if HAVE_SNPRINTF
       if (__date)
        snprintf (date, DATE_LEN + 1, "%04d%02d%02d",
                  values[0], values[1], values[2]);
@@ -193,18 +173,6 @@ date_and_time (char *__date, char *__time, char *__zone,
       if (__zone)
        snprintf (zone, ZONE_LEN + 1, "%+03d%02d",
                  values[3] / 60, abs (values[3] % 60));
-#else
-      if (__date)
-       sprintf (date, "%04d%02d%02d", values[0], values[1], values[2]);
-
-      if (__time)
-       sprintf (timec, "%02d%02d%02d.%03d",
-                values[4], values[5], values[6], values[7]);
-
-      if (__zone)
-       sprintf (zone, "%+03d%02d",
-                values[3] / 60, abs (values[3] % 60));
-#endif
     }
   else
     {
@@ -220,21 +188,6 @@ date_and_time (char *__date, char *__time, char *__zone,
       for (i = 0; i < VALUES_SIZE; i++)
        values[i] = - GFC_INTEGER_4_HUGE;
     }   
-#else /* if defined HAVE_NO_DATE_TIME  */
-  /* We really have *nothing* to return, so return blanks and HUGE(0).  */
-      
-  memset (date, ' ', DATE_LEN);
-  date[DATE_LEN] = '\0';
-
-  memset (timec, ' ', TIME_LEN);
-  timec[TIME_LEN] = '\0';
-
-  memset (zone, ' ', ZONE_LEN);
-  zone[ZONE_LEN] = '\0';
-
-  for (i = 0; i < VALUES_SIZE; i++)
-    values[i] = - GFC_INTEGER_4_HUGE;
-#endif  /* HAVE_NO_DATE_TIME  */
 
   /* Copy the values into the arguments.  */
   if (__values)
@@ -348,7 +301,6 @@ secnds (GFC_REAL_4 *x)
 static void
 itime0 (int x[3])
 {
-#ifndef HAVE_NO_DATE_TIME
   time_t lt;
   struct tm local_time;
 
@@ -362,9 +314,6 @@ itime0 (int x[3])
       x[1] = local_time.tm_min;
       x[2] = local_time.tm_sec;
     }
-#else
-  x[0] = x[1] = x[2] = -1;
-#endif
 }
 
 extern void itime_i4 (gfc_array_i4 *);
@@ -430,7 +379,6 @@ itime_i8 (gfc_array_i8 *__values)
 static void
 idate0 (int x[3])
 {
-#ifndef HAVE_NO_DATE_TIME
   time_t lt;
   struct tm local_time;
 
@@ -444,9 +392,6 @@ idate0 (int x[3])
       x[1] = 1 + local_time.tm_mon;
       x[2] = 1900 + local_time.tm_year;
     }
-#else
-  x[0] = x[1] = x[2] = -1;
-#endif
 }
 
 extern void idate_i4 (gfc_array_i4 *);