{
// FUNCTION CURRENT-DATE
struct cbl_timespec tp = {};
- __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec
+ __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec
char retval[DATE_STRING_BUFFER_SIZE];
timespec_to_string(retval, tp);
struct tm tm;
__int128 retval=0;
- __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec
+ __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec
localtime_r(&tp.tv_sec, &tm);
retval += tm.tm_hour;
size_t input_offset,
size_t input_size)
{
- // FUNCTION CURRENT-DATE
+ // FUNCTION FORMATTED-CURRENT-DATE
// Establish the destination, and set it to spaces
char *d = PTRCAST(char, dest->data);
}
struct cbl_timespec ts = {};
- __gg__clock_gettime(CLOCK_REALTIME, &ts);
+ __gg__clock_gettime(&ts);
struct tm tm = {};
#ifdef HAVE_STRUCT_TM_TM_ZONE
state = (char *)malloc(state_len);
struct cbl_timespec ts;
- __gg__clock_gettime(CLOCK_REALTIME, &ts);
+ __gg__clock_gettime(&ts);
initstate_r( ts.tv_nsec, state, state_len, buf);
}
int seed = (int)__gg__binary_value_from_qualified_field(&rdigits,
buf->state = NULL;
state = (char *)malloc(state_len);
struct cbl_timespec ts;
- __gg__clock_gettime(CLOCK_REALTIME, &ts);
+ __gg__clock_gettime(&ts);
initstate_r( ts.tv_nsec, state, state_len, buf);
}
random_r(buf, &retval_31);
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/time.h>
#include <execinfo.h>
#include "exceptl.h"
, operation(file_op_none)
, mode(file_mode_none_e)
, user_status(nullptr)
- , filename(nullptr)
+ , filename(nullptr)
{}
explicit file_status_t( const cblc_file_t *file )
: ifile(file->symbol_table_index)
abort();
}
-void
+void
__gg__mabort()
{
__gg__abort("Memory allocation error\n");
cobol_time()
{
struct cbl_timespec tp;
- __gg__clock_gettime(CLOCK_REALTIME, &tp);
+ __gg__clock_gettime(&tp);
return tp.tv_sec;
}
return retval;
}
-uint64_t
-get_time_nanoseconds()
+// For testing purposes, this undef causes the use of gettimeofday().
+// #undef HAVE_CLOCK_GETTIME
+
+static uint64_t
+get_time_nanoseconds_local()
{
// This code was unabashedly stolen from gcc/timevar.cc.
// It returns the Unix epoch with nine decimal places.
+ /* Note: I am perplexed. I have been examining the gcc Makefiles and
+ configure.ac files, and I am unable to locate where HAVE_GETTIMEOFDAY
+ is established. There have been issues compiling on MacOS, where
+ apparently clock_gettime() is not available. But I don't see exactly
+ how gettimeofday() gets used, instead. But without the ability to
+ compile on a MacOS system, I am fumbling along as best I can.
+
+ I decided to simply replace clock_gettime() with getttimeofday() when
+ clock_gettime() isn't available, even though gcc/timevar.cc handles
+ the situation differently.
+
+ -- Bob Dubner, 2025-06-11*/
+
uint64_t retval = 0;
#ifdef HAVE_CLOCK_GETTIME
clock_gettime (CLOCK_REALTIME, &ts);
retval = ts.tv_sec * 1000000000 + ts.tv_nsec;
return retval;
-#endif
-#ifdef HAVE_GETTIMEOFDAY
+//#endif
+//#ifdef HAVE_GETTIMEOFDAY
+#else
struct timeval tv;
gettimeofday (&tv, NULL);
retval = tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
extern "C"
void
-__gg__clock_gettime(clockid_t clk_id, struct cbl_timespec *tp)
+__gg__clock_gettime(struct cbl_timespec *tp)
{
const char *p = getenv("GCOBOL_CURRENT_DATE");
}
else
{
- timespec tm;
- clock_gettime(clk_id, &tm);
- uint64_t ns = get_time_nanoseconds();
+ uint64_t ns = get_time_nanoseconds_local();
tp->tv_sec = ns/1000000000;
tp->tv_nsec = ns%1000000000;
}
char ach[32];
struct cbl_timespec tv;
- __gg__clock_gettime(CLOCK_REALTIME, &tv);
+ __gg__clock_gettime(&tv);
struct tm tm;
localtime_r(&tv.tv_sec, &tm);
}
else
{
- cmpval = cstrncmp (test,
+ cmpval = cstrncmp (test,
PTRCAST(char, conditional_location),
conditional_length);
if( cmpval == 0 && (int)strlen(test) != conditional_length )
}
static size_t right_string_size = MINIMUM_ALLOCATION_SIZE;
- static char *right_string
+ static char *right_string
= static_cast<char *>(malloc(right_string_size));
right_string = format_for_display_internal(