This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch main
in repository eternity.

View the commit online.

commit 3a54089821019e9040164312aa69dd5bff55d541
Author: Vincent Torri <[email protected]>
AuthorDate: Sun Nov 22 09:18:11 2026 +0100

    add compat layer for localtime_r() and realpath()
---
 src/lib/eternity_alarm.c     |  3 ++-
 src/lib/eternity_clock.c     | 10 ++++++----
 src/lib/eternity_compat.h    | 26 ++++++++++++++++++++++++++
 src/lib/eternity_world.c     |  3 ++-
 tests/eternity_config_test.c |  3 ++-
 5 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/src/lib/eternity_alarm.c b/src/lib/eternity_alarm.c
index 9c15f05..2f8bada 100644
--- a/src/lib/eternity_alarm.c
+++ b/src/lib/eternity_alarm.c
@@ -1,3 +1,4 @@
+#include "eternity_compat.h"
 #include "eternity.h"
 #include "eternity_clock.h"
 #include <math.h>
@@ -163,7 +164,7 @@ _eternity_alarm_status_update(Eternity *app)
          else if (app->config->scheduled_deadline > 0)
             {
                deadline = (time_t)app->config->scheduled_deadline;
-               if (localtime_r(&deadline, &local))
+               if (eternity_localtime(&deadline, &local))
                   strftime(text, sizeof(text), _("Next alarm: %a %d %b, %H:%M %Z"), &local);
                else snprintf(text, sizeof(text), "%s", _("Alarm is set"));
             }
diff --git a/src/lib/eternity_clock.c b/src/lib/eternity_clock.c
index d2bf90a..6154f09 100644
--- a/src/lib/eternity_clock.c
+++ b/src/lib/eternity_clock.c
@@ -1,3 +1,4 @@
+#include "eternity_compat.h"
 #include "eternity_clock.h"
 #include "eternity_build.h"
 #include <limits.h>
@@ -69,7 +70,8 @@ eternity_clock_time_get(const char *zone, time_t now, struct tm *result)
    Eina_Bool ok;
 
    /* TZ is process-wide. Call only from the UI thread, never a worker. */
-   if (zone && !strcmp(zone, "local")) return localtime_r(&now, result) != NULL;
+   if (zone && !strcmp(zone, "local"))
+     return eternity_localtime(&now, result) != NULL;
    if (!_eternity_clock_zone_path_get(zone, tz + 1, sizeof(tz) - 1)) return EINA_FALSE;
 
    current = getenv("TZ");
@@ -84,7 +86,7 @@ eternity_clock_time_get(const char *zone, time_t now, struct tm *result)
 
    tzset();
 
-   ok = localtime_r(&now, result) != NULL;
+   ok = eternity_localtime(&now, result);
    if (saved) setenv("TZ", saved, 1);
    else unsetenv("TZ");
    tzset();
@@ -110,7 +112,7 @@ eternity_clock_alarm_next(time_t now, int hour, int minute)
 
    if (hour < 0 || hour > 23 || minute < 0 || minute > 59) return (time_t)-1;
 
-   if (!localtime_r(&now, &local)) return (time_t)-1;
+   if (!eternity_localtime(&now, &local)) return (time_t)-1;
 
    for (day = 0; day < 3; day++)
       {
@@ -134,7 +136,7 @@ eternity_clock_alarm_next(time_t now, int hour, int minute)
                target.tm_isdst = dst;
 
                candidate = mktime(&target);
-               if (candidate == (time_t)-1 || !localtime_r(&candidate, &actual)) continue;
+               if (candidate == (time_t)-1 || !eternity_localtime(&candidate, &actual)) continue;
                if (actual.tm_year != calendar.tm_year || actual.tm_yday != calendar.tm_yday)
                   continue;
                if (actual.tm_hour == hour && actual.tm_min == minute)
diff --git a/src/lib/eternity_compat.h b/src/lib/eternity_compat.h
new file mode 100644
index 0000000..f59cc65
--- /dev/null
+++ b/src/lib/eternity_compat.h
@@ -0,0 +1,26 @@
+#ifndef ETERNITY_COMPAT_H
+#define ETERNITY_COMPAT_H
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <time.h>
+
+static inline bool eternity_localtime(const time_t *timep, struct tm *result)
+{
+#ifdef _WIN32
+  return localtime_s(result, timep) == 0;
+#else
+  return localtime_r(timep, result) != NULL;
+#endif
+}
+
+static inline char *eternity_realpath(const char *path)
+{
+#ifdef _WIN32
+  return _fullpath(NULL, path, 0);
+#else
+   return realpath(path, NULL);
+#endif
+}
+
+#endif
diff --git a/src/lib/eternity_world.c b/src/lib/eternity_world.c
index 4746eef..24117ed 100644
--- a/src/lib/eternity_world.c
+++ b/src/lib/eternity_world.c
@@ -1,3 +1,4 @@
+#include "eternity_compat.h"
 #include "eternity_world.h"
 #include "eternity_clock.h"
 #include "eternity_intl.h"
@@ -80,7 +81,7 @@ eternity_world_location_get(const char *zone, double *latitude, double *longitud
       {
          tz = getenv("TZ");
          if (tz && tz[0]) zone = tz[0] == ':' ? tz + 1 : tz;
-         else if (realpath("/etc/localtime", resolved) && strstr(resolved, "/zoneinfo/"))
+         else if (eternity_realpath("/etc/localtime", resolved) && strstr(resolved, "/zoneinfo/"))
             zone = strstr(resolved, "/zoneinfo/") + strlen("/zoneinfo/");
          else
             {
diff --git a/tests/eternity_config_test.c b/tests/eternity_config_test.c
index 64d4274..a250f50 100644
--- a/tests/eternity_config_test.c
+++ b/tests/eternity_config_test.c
@@ -1,3 +1,4 @@
+#include "eternity_compat.h"
 #include "eternity_config.h"
 #include "eternity_clock.h"
 #include <Elementary.h>
@@ -72,7 +73,7 @@ _eternity_test_scheduled_times(void)
    now = _eternity_test_local(2026, 3, 29, 0, 30, 0);
    next = eternity_clock_alarm_next(now, 1, 30);
 
-   assert(localtime_r(&next, &local) && local.tm_mday == 29 && local.tm_hour == 2
+   assert(eternity_localtime(&next, &local) && local.tm_mday == 29 && local.tm_hour == 2
           && local.tm_min == 30);
 
    /* During the autumn repeated hour, use the second occurrence if the first passed. */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to