From 1474885024c5009549e560dcec749654462705ac Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Fri, 17 Apr 2026 23:13:37 -0400 Subject: [PATCH] Revisions to allow compiling under Windows-mingw64 --- include/cron.h | 36 ++++++++++++++++++++++++++++++++++++ src/pg_cron.c | 17 ++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/cron.h b/include/cron.h index f906235..8309213 100644 --- a/include/cron.h +++ b/include/cron.h @@ -28,7 +28,43 @@ /* reorder these #include's at your peril */ +#ifndef WIN32_COMPAT_H +#define WIN32_COMPAT_H + +#ifdef _WIN32 +#include +#include + + + +/* Fix missing POSIX types */ +#ifndef uid_t +typedef int uid_t; +typedef int gid_t; +#endif + +#ifndef uint +typedef unsigned int uint; +#endif + +/* Fix poll mapping */ +#define poll WSAPoll + +/* Stub out rlimit to satisfy the compiler without using port.h */ +struct rlimit { + uint rlim_cur; + uint rlim_max; +}; +#define RLIMIT_NOFILE 0 +static inline int getrlimit(int resource, struct rlimit *rlp) { return 0; } + +#endif /* _WIN32 */ +#endif /* WIN32_COMPAT_H */ + + #include + + #include #include diff --git a/src/pg_cron.c b/src/pg_cron.c index e4eb4fc..a828f50 100644 --- a/src/pg_cron.c +++ b/src/pg_cron.c @@ -11,7 +11,19 @@ * *------------------------------------------------------------------------- */ + +/** move this first so windows gets the winsock early */ +#include "cron.h" + +#if defined(_WIN32) && (PG_VERSION_NUM < 160000) +/* +* Skip sys/resource.h for PG15 and lower on Windows +* this is only an issue with PG < 16 for windows cause of the changes in 16 and above for windows +*/ +#else #include +#endif + #include "postgres.h" #include "fmgr.h" @@ -30,7 +42,6 @@ /* these headers are used by this particular worker's code */ #define MAIN_PROGRAM -#include "cron.h" #include "pg_cron.h" #include "task_states.h" @@ -1508,7 +1519,7 @@ ManageCronTask(CronTask *task, TimestampTz currentTime) task->lastStartTime = GetCurrentTimestamp(); if (CronLogRun) - UpdateJobRunDetail(task->runId, &pid, GetCronStatus(CRON_STATUS_RUNNING), NULL, &task->lastStartTime, NULL); + UpdateJobRunDetail(task->runId, (int32 *) &pid, GetCronStatus(CRON_STATUS_RUNNING), NULL, &task->lastStartTime, NULL); task->state = CRON_TASK_BGW_RUNNING; break; @@ -1556,7 +1567,7 @@ ManageCronTask(CronTask *task, TimestampTz currentTime) pid = (pid_t) PQbackendPID(connection); if (CronLogRun) - UpdateJobRunDetail(task->runId, &pid, GetCronStatus(CRON_STATUS_SENDING), NULL, NULL, NULL); + UpdateJobRunDetail(task->runId, (int32 *) &pid, GetCronStatus(CRON_STATUS_SENDING), NULL, NULL, NULL); } else if (pollingStatus == PGRES_POLLING_FAILED) {