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 52bf91e6729ebd0fac0e98ec4bec0a94a09e9bbc
Author: Vincent Torri <[email protected]>
AuthorDate: Tue Nov 24 22:20:18 2026 +0100

    add setenv() support on Windows
---
 src/lib/eternity_alarm.c     |  8 +++++---
 src/lib/eternity_clock.c     |  6 +++---
 src/lib/eternity_compat.h    | 27 +++++++++++++++++++++++++++
 src/lib/eternity_world.c     | 15 ++++++++++-----
 tests/eternity_config_test.c | 25 ++++++++++++++-----------
 5 files changed, 59 insertions(+), 22 deletions(-)

diff --git a/src/lib/eternity_alarm.c b/src/lib/eternity_alarm.c
index 2f8bada..ac35713 100644
--- a/src/lib/eternity_alarm.c
+++ b/src/lib/eternity_alarm.c
@@ -1,11 +1,13 @@
-#include "eternity_compat.h"
-#include "eternity.h"
-#include "eternity_clock.h"
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "eternity_compat.h"
+#include "eternity.h"
+#include "eternity_clock.h"
+
 static void
 _eternity_alarm_status_update(Eternity *app);
 
diff --git a/src/lib/eternity_clock.c b/src/lib/eternity_clock.c
index 30c2d5a..8d2ec2b 100644
--- a/src/lib/eternity_clock.c
+++ b/src/lib/eternity_clock.c
@@ -77,7 +77,7 @@ eternity_clock_time_get(const char *zone, time_t now, struct tm *result)
    current = getenv("TZ");
    saved = current ? strdup(current) : NULL;
    if (current && !saved) return EINA_FALSE;
-   if (setenv("TZ", tz, 1))
+   if (eternity_setenv("TZ", tz, 1))
       {
          free(saved);
 
@@ -87,8 +87,8 @@ eternity_clock_time_get(const char *zone, time_t now, struct tm *result)
    tzset();
 
    ok = eternity_localtime(&now, result);
-   if (saved) setenv("TZ", saved, 1);
-   else unsetenv("TZ");
+   if (saved) eternity_setenv("TZ", saved, 1);
+   else eternity_unsetenv("TZ");
    tzset();
    free(saved);
 
diff --git a/src/lib/eternity_compat.h b/src/lib/eternity_compat.h
index f59cc65..b6ff803 100644
--- a/src/lib/eternity_compat.h
+++ b/src/lib/eternity_compat.h
@@ -5,6 +5,12 @@
 #include <stdlib.h>
 #include <time.h>
 
+#ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#undef WIN32_LEAN_AND_MEAN
+
 static inline bool eternity_localtime(const time_t *timep, struct tm *result)
 {
 #ifdef _WIN32
@@ -23,4 +29,25 @@ static inline char *eternity_realpath(const char *path)
 #endif
 }
 
+static inline bool eternity_setenv(const char *name, const char *value, int overwrite)
+{
+#ifdef _WIN32
+   if (overwrite)
+     SetEnvironmentVariable(name, NULL);
+
+   return SetEnvironmentVariable(name, value) == 0;
+#else
+   return setenv(name, value, overwrite) == 0;
+#endif
+}
+
+static inline bool eternity_unsetenv(const char *name)
+{
+#ifdef _WIN32
+   return SetEnvironmentVariable(name, NULL) == 0;
+#else
+   return unsetenv(name);
+#endif
+}
+
 #endif
diff --git a/src/lib/eternity_world.c b/src/lib/eternity_world.c
index b2ecac2..577fd49 100644
--- a/src/lib/eternity_world.c
+++ b/src/lib/eternity_world.c
@@ -1,13 +1,18 @@
-#include "eternity_compat.h"
-#include "eternity_world.h"
-#include "eternity_clock.h"
-#include "eternity_intl.h"
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
-#include <unistd.h>
+
+#ifndef _WIN32
+# include <unistd.h>
+#endif
+
+#include "eternity_compat.h"
+#include "eternity_world.h"
+#include "eternity_clock.h"
+#include "eternity_intl.h"
 
 #define ETERNITY_RAD (M_PI / 180.0)
 #define ETERNITY_MAP_WIDTH 720
diff --git a/tests/eternity_config_test.c b/tests/eternity_config_test.c
index a250f50..152b60e 100644
--- a/tests/eternity_config_test.c
+++ b/tests/eternity_config_test.c
@@ -1,13 +1,16 @@
-#include "eternity_compat.h"
-#include "eternity_config.h"
-#include "eternity_clock.h"
-#include <Elementary.h>
-#include <Efreet.h>
-#include <Ecore_File.h>
+
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <Elementary.h>
+#include <Efreet.h>
+#include <Ecore_File.h>
+
+#include "eternity_compat.h"
+#include "eternity_config.h"
+#include "eternity_clock.h"
+
 static void
 _eternity_test_legacy_config_write(void)
 {
@@ -54,7 +57,7 @@ _eternity_test_scheduled_times(void)
    time_t now, next;
    struct tm local;
 
-   setenv("TZ", "UTC", 1);
+   eternity_setenv("TZ", "UTC", 1);
    tzset();
 
    now = _eternity_test_local(2026, 12, 31, 23, 50, -1);
@@ -64,7 +67,7 @@ _eternity_test_scheduled_times(void)
    assert(eternity_clock_alarm_next(now, 8, 30) == now + 86400);
    assert(eternity_clock_alarm_next(now, 9, 0) == now + 1800);
    assert(eternity_clock_alarm_next(now, 24, 0) == (time_t)-1);
-   setenv("TZ", "Europe/London", 1);
+   eternity_setenv("TZ", "Europe/London", 1);
    tzset();
 
    now = _eternity_test_local(2026, 3, 28, 12, 0, -1);
@@ -83,7 +86,7 @@ _eternity_test_scheduled_times(void)
    /* A summer alarm already passed must not become an hour-late alarm today. */
    now = _eternity_test_local(2026, 7, 1, 8, 45, 1);
    assert(eternity_clock_alarm_next(now, 8, 30) == _eternity_test_local(2026, 7, 2, 8, 30, 1));
-   unsetenv("TZ");
+   eternity_unsetenv("TZ");
    tzset();
 }
 
@@ -136,12 +139,12 @@ main(void)
    assert(!strcmp(clock->label, "London <&>"));
    assert(!strcmp(clock->zone, "Europe/London"));
 
-   setenv("TZ", "UTC", 1);
+   eternity_setenv("TZ", "UTC", 1);
    tzset();
    assert(eternity_clock_time_get("Europe/London", 1782907200, &time));
    assert(time.tm_hour == 13); /* July 1, 2026: British Summer Time. */
    assert(!strcmp(getenv("TZ"), "UTC"));
-   unsetenv("TZ");
+   eternity_unsetenv("TZ");
    tzset();
    assert(eternity_clock_time_get("UTC", 0, &time));
    assert(time.tm_hour == 0 && !getenv("TZ"));

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

Reply via email to