fix(portability): compute UTC timestamps without timegm so macOS clang builds cleanly
timegm() is not declared on macOS by default and is absent on Windows. The conversion is now done with Howard Hinnant's civil-date arithmetic, which is exact for the whole range this plugin searches. The next-run horizon is widened to twenty years so even 29 February yields five timestamps.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 04:59:48
Commite8f18498
Parents4ee35824
Changed files
README.md+1−1■■
src/plugin_crontab.c+21−6■■■■■
2 files+22−7
Diff
README.md+1−1■■
index eb4c10d..d855f10 100644
--- a/README.md
+++ b/README.md
@@ -172,7 +172,7 @@ Plugin identity, version, supported actions, capabilities and the trust notice.
172172 - **No network.** No sockets, no HTTP client, no telemetry.
173173 - **Two external programs, both query-only:** `crontab -l` and `schtasks /Query`.
174174 - **No user input reaches a shell.** Fixture paths come from the environment, not the query.
175-- **Next-run horizon** is four years, which covers every expression including
175+- **Next-run horizon** is twenty years, which covers every expression including
176176 `0 0 29 2 *` (29 February) and `0 0 1 1 *` (1 January).
177177
178178 ---
src/plugin_crontab.c+21−6■■■■■
index 7524065..2c1c785 100644
--- a/src/plugin_crontab.c
+++ b/src/plugin_crontab.c
@@ -52,7 +52,7 @@
5252 #define MAX_CMD 512
5353 #define MAX_SRC 64
5454 #define MAX_RUNS 5
55-#define HORIZON_DAYS 1461
55+#define HORIZON_DAYS 7305 /* twenty years: five runs even for 29 February */
5656 #define READ_LINE 2048
5757
5858 /* ------------------------------------------------------------------ */
@@ -332,13 +332,28 @@ static int count_set(const unsigned char *flags, int lo, int hi)
332332 /* Portable UTC mktime */
333333 /* ---------------------------------------------------------------- */
334334
335+/* Days since the Unix epoch for a civil date (Howard Hinnant's algorithm). */
336+static long days_from_civil(int y, int m, int d)
337+{
338+ long era, yoe, doy, doe;
339+
340+ y -= (m <= 2);
341+ era = (y >= 0 ? y : y - 399) / 400;
342+ yoe = (long)(y - era * 400);
343+ doy = (153L * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1;
344+ doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
345+ return era * 146097L + doe - 719468L;
346+}
347+
348+/*
349+ * Portable UTC mktime. Implemented directly rather than calling timegm(),
350+ * which is not declared by default on macOS and is missing on Windows.
351+ */
335352 static time_t timegm_portable(struct tm *tmv)
336353 {
337-#if defined(_WIN32)
338- return _mkgmtime(tmv);
339-#else
340- return timegm(tmv);
341-#endif
354+ long days = days_from_civil(tmv->tm_year + 1900, tmv->tm_mon + 1, tmv->tm_mday);
355+ return (time_t)(days * 86400L + (long)tmv->tm_hour * 3600L
356+ + (long)tmv->tm_min * 60L + (long)tmv->tm_sec);
342357 }
343358 /* ---------------------------------------------------------------- */
344359 /* Human readable description of a parsed schedule */
345360
README.md+1−1■■
index eb4c10d..d855f10 100644index eb4c10d..d855f10 100644
--- a/README.md--- a/README.md
+++ b/README.md+++ b/README.md
@@ -172,7 +172,7 @@ Plugin identity, version, supported actions, capabilities and the trust notice.@@ -172,7 +172,7 @@ Plugin identity, version, supported actions, capabilities and the trust notice.
172 - **No network.** No sockets, no HTTP client, no telemetry.172 - **No network.** No sockets, no HTTP client, no telemetry.
173 - **Two external programs, both query-only:** `crontab -l` and `schtasks /Query`.173 - **Two external programs, both query-only:** `crontab -l` and `schtasks /Query`.
174 - **No user input reaches a shell.** Fixture paths come from the environment, not the query.174 - **No user input reaches a shell.** Fixture paths come from the environment, not the query.
175-- **Next-run horizon** is four years, which covers every expression including175+- **Next-run horizon** is twenty years, which covers every expression including
176 `0 0 29 2 *` (29 February) and `0 0 1 1 *` (1 January).176 `0 0 29 2 *` (29 February) and `0 0 1 1 *` (1 January).
177 177
178 ---178 ---
src/plugin_crontab.c+21−6■■■■■
index 7524065..2c1c785 100644index 7524065..2c1c785 100644
--- a/src/plugin_crontab.c--- a/src/plugin_crontab.c
+++ b/src/plugin_crontab.c+++ b/src/plugin_crontab.c
@@ -52,7 +52,7 @@@@ -52,7 +52,7 @@
52 #define MAX_CMD 51252 #define MAX_CMD 512
53 #define MAX_SRC 6453 #define MAX_SRC 64
54 #define MAX_RUNS 554 #define MAX_RUNS 5
55-#define HORIZON_DAYS 146155+#define HORIZON_DAYS 7305 /* twenty years: five runs even for 29 February */
56 #define READ_LINE 204856 #define READ_LINE 2048
57 57
58 /* ------------------------------------------------------------------ */58 /* ------------------------------------------------------------------ */
@@ -332,13 +332,28 @@ static int count_set(const unsigned char *flags, int lo, int hi)@@ -332,13 +332,28 @@ static int count_set(const unsigned char *flags, int lo, int hi)
332 /* Portable UTC mktime */332 /* Portable UTC mktime */
333 /* ---------------------------------------------------------------- */333 /* ---------------------------------------------------------------- */
334 334
335+/* Days since the Unix epoch for a civil date (Howard Hinnant's algorithm). */
336+static long days_from_civil(int y, int m, int d)
337+{
338+ long era, yoe, doy, doe;
339+
340+ y -= (m <= 2);
341+ era = (y >= 0 ? y : y - 399) / 400;
342+ yoe = (long)(y - era * 400);
343+ doy = (153L * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1;
344+ doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
345+ return era * 146097L + doe - 719468L;
346+}
347+
348+/*
349+ * Portable UTC mktime. Implemented directly rather than calling timegm(),
350+ * which is not declared by default on macOS and is missing on Windows.
351+ */
335 static time_t timegm_portable(struct tm *tmv)352 static time_t timegm_portable(struct tm *tmv)
336 {353 {
337-#if defined(_WIN32)354+ long days = days_from_civil(tmv->tm_year + 1900, tmv->tm_mon + 1, tmv->tm_mday);
338- return _mkgmtime(tmv);355+ return (time_t)(days * 86400L + (long)tmv->tm_hour * 3600L
339-#else356+ + (long)tmv->tm_min * 60L + (long)tmv->tm_sec);
340- return timegm(tmv);
341-#endif
342 }357 }
343 /* ---------------------------------------------------------------- */358 /* ---------------------------------------------------------------- */
344 /* Human readable description of a parsed schedule */359 /* Human readable description of a parsed schedule */
345360