]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975]
authorRobert Dubner <rdubner@symas.com>
Mon, 2 Jun 2025 19:55:20 +0000 (15:55 -0400)
committerRobert Dubner <rdubner@symas.com>
Mon, 2 Jun 2025 20:24:52 +0000 (16:24 -0400)
These changes cause genapi.cc to use whichever of clock_gettime() or
gettimeofday() are available.  This prevents compilation errors on
systems where clock_gettime() is not available.

gcc/cobol/ChangeLog:

PR cobol/119975
* genapi.cc (parser_intrinsic_call_0): Use get_time_64() function.
* genutil.cc (get_time_64): Definition created.
* genutil.h (get_time_64): Declaration created.

gcc/cobol/genapi.cc
gcc/cobol/genutil.cc
gcc/cobol/genutil.h

index 2ce9cad5c0d668a2373ee314e1cb3c4d66609044..5e983ab503c2689adc15f23785e12d171b31e0eb 100644 (file)
@@ -10491,7 +10491,9 @@ parser_intrinsic_call_0(cbl_field_t *tgt,
     {
     // Pass __gg__when_compiled() the time from right now.
     struct timespec tp;
-    clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec
+    uint64_t now = get_time_64();
+    tp.tv_sec  = now / 1000000000;
+    tp.tv_nsec = now % 1000000000;
 
     store_location_stuff(function_name);
     gg_call(VOID,
index d0aaf2b3215f1c6b8049ed79fc9fea291e2b3b6b..e971043164c799d7975892fa47d8484903c8fc72 100644 (file)
@@ -2119,3 +2119,26 @@ qualified_data_location(cbl_refer_t &refer)
   return gg_add(member(refer.field->var_decl_node, "data"),
                 refer_offset(refer));
   }
+
+uint64_t
+get_time_64()
+{
+  // This code was unabashedly stolen from gcc/timevar.cc.
+  // It returns the Unix epoch with nine decimal places.
+
+  uint64_t retval = 0;
+
+#ifdef HAVE_CLOCK_GETTIME
+  struct timespec ts;
+  clock_gettime (CLOCK_REALTIME, &ts);
+  retval = ts.tv_sec * 1000000000 + ts.tv_nsec;
+  return retval;
+#endif
+#ifdef HAVE_GETTIMEOFDAY
+  struct timeval tv;
+  gettimeofday (&tv, NULL);
+  retval = tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+  return retval;
+#endif
+  return retval;
+}
\ No newline at end of file
index 2f4bc36eace7aeaf29a2644ba1e7219a2a2e307a..43102d7cc5442a45f5dd4d229e6adfcc0de46c69 100644 (file)
@@ -155,4 +155,7 @@ void      build_array_of_fourplets( int ngroup,
                                     size_t N,
                                     cbl_refer_t *refers);
 void      get_depending_on_value_from_odo(tree retval, cbl_field_t *odo);
+uint64_t  get_time_64();
+
+
 #endif