From 76bd3afdf82f202c7dcf43ff452315cb513a119e Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Mon, 29 Jun 2026 12:38:27 -0500 Subject: [PATCH] feat(dist): Win32 POSIX shim for el_runtime.c cross-compilation --- dist/win32_shim.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dist/win32_shim.h diff --git a/dist/win32_shim.h b/dist/win32_shim.h new file mode 100644 index 0000000..70577c6 --- /dev/null +++ b/dist/win32_shim.h @@ -0,0 +1,35 @@ +/* + * win32_shim.h — Extra POSIX→Win32 stubs for cross-compiling el_runtime.c with mingw-w64. + * Injected via -include; supplements el_platform_win.h for symbols it doesn't yet cover. + */ +#ifdef _WIN32 +#include + +/* ── rusage / getrusage ────────────────────────────────────────────────────── */ +/* el_runtime.c uses getrusage(RUSAGE_SELF) only for a soft memory guard. + * On Windows, stub it out: always return 0 ru_maxrss so the guard never fires. */ +#ifndef RUSAGE_SELF +#define RUSAGE_SELF 0 +struct rusage { + long ru_maxrss; /* the only field el_runtime actually reads */ +}; +static inline int getrusage(int who, struct rusage *r) { + (void)who; + if (r) r->ru_maxrss = 0; + return 0; +} +#endif /* RUSAGE_SELF */ + +/* ── fsync ─────────────────────────────────────────────────────────────────── */ +/* Windows has FlushFileBuffers but no fsync; map it. */ +#ifndef fsync +#include +static inline int el_win_fsync(int fd) { + HANDLE h = (HANDLE)_get_osfhandle(fd); + if (h == INVALID_HANDLE_VALUE) return -1; + return FlushFileBuffers(h) ? 0 : -1; +} +#define fsync(fd) el_win_fsync(fd) +#endif /* fsync */ + +#endif /* _WIN32 */