From 63fb0bedb8077ac1e6b6337f198b4eae30813fbc Mon Sep 17 00:00:00 2001 From: Gaius Mulley Date: Sat, 12 Aug 2023 18:17:41 +0100 Subject: PR modula2/110779 SysClock can not read the clock (Darwin portability fixes) This patch adds corrections to defensively check against glibc functions, structures and contains fallbacks. These fixes were required under Darwin. gcc/m2/ChangeLog: PR modula2/110779 * gm2-libs-iso/SysClock.mod (EpochTime): New procedure. (GetClock): Call EpochTime if the C time functions are unavailable. * gm2-libs-iso/wrapclock.def (istimezone): New function definition. libgm2/ChangeLog: PR modula2/110779 * configure: Regenerate. * configure.ac: Provide special case test for Darwin cross configuration. (GLIBCXX_CONFIGURE): New statement. (GLIBCXX_CHECK_GETTIMEOFDAY): New statement. (GLIBCXX_ENABLE_LIBSTDCXX_TIME): New statement. * libm2iso/wrapclock.cc: New sys/time.h conditional include. (sys/syscall.h): Conditional include. (unistd.h): Conditional include. (GetTimeRealtime): Re-implement. (SetTimeRealtime): Re-implement. (timezone): Re-implement. (istimezone): New function. (daylight): Re-implement. (isdst): Re-implement. (tzname): Re-implement. Signed-off-by: Gaius Mulley --- gcc/m2/gm2-libs-iso/SysClock.mod | 34 ++++++++++++++++++++++++++-------- gcc/m2/gm2-libs-iso/wrapclock.def | 12 ++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) (limited to 'gcc') diff --git a/gcc/m2/gm2-libs-iso/SysClock.mod b/gcc/m2/gm2-libs-iso/SysClock.mod index 3313309..56d5503 100644 --- a/gcc/m2/gm2-libs-iso/SysClock.mod +++ b/gcc/m2/gm2-libs-iso/SysClock.mod @@ -173,6 +173,26 @@ BEGIN END ExtractDate ; +(* + EpochTime - assigns all fields of userData to 0 or FALSE. +*) + +PROCEDURE EpochTime (VAR userData: DateTime) ; +BEGIN + WITH userData DO + second := 0 ; + minute := 0 ; + hour := 0 ; + year := 0 ; + month := 0 ; + day := 0 ; + fractions := 0 ; + zone := 0 ; + summerTimeFlag := FALSE + END +END EpochTime ; + + PROCEDURE GetClock (VAR userData: DateTime) ; (* Assigns local date and time of the day to userData *) VAR @@ -207,10 +227,10 @@ BEGIN summerTimeFlag := (isdst () = 1) END ELSE - HALT + EpochTime (userData) END ELSE - HALT + EpochTime (userData) END ; ts := KillTimespec (ts) END @@ -310,13 +330,11 @@ BEGIN userData.month, userData.year) ; offset := timezone () ; sec := VAL (LONGINT, sec) - offset ; - IF SetTimespec (ts, sec, nano) = 0 - THEN - HALT - END ; - IF SetTimeRealtime (ts) # 0 + IF SetTimespec (ts, sec, nano) = 1 THEN - HALT + IF SetTimeRealtime (ts) = 0 + THEN + END END ; ts := KillTimespec (ts) END diff --git a/gcc/m2/gm2-libs-iso/wrapclock.def b/gcc/m2/gm2-libs-iso/wrapclock.def index 1dd12e1..9f5f286 100644 --- a/gcc/m2/gm2-libs-iso/wrapclock.def +++ b/gcc/m2/gm2-libs-iso/wrapclock.def @@ -36,12 +36,24 @@ TYPE timezone - return the glibc timezone value. This contains the difference between UTC and the latest local standard time, in seconds west of UTC. + If the underlying timezone is unavailable and + clock_gettime, localtime_r, tm_gmtoff + is unavailable then 0 is returned. *) PROCEDURE timezone () : LONGINT ; (* + istimezone returns 1 if timezone in wrapclock.cc can resolve the + timezone value using the timezone C library call or by using + clock_gettime, localtime_r and tm_gmtoff. +*) + +PROCEDURE istimezone () : INTEGER ; + + +(* daylight - return the glibc daylight value. This variable has a nonzero value if Daylight Saving Time rules apply. -- cgit v1.1