/*
 * 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 <windows.h>

/* ── 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 <io.h>
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 */
