Skip to content

Commit dd0f801

Browse files
committed
fix(win): add Windows branch to pb_rss_kb + link psapi
CI Windows builds failed in printable_binary.c with: error: call to undeclared function 'sysconf' error: use of undeclared identifier '_SC_PAGESIZE' Fix: extend the pb_rss_kb() RSS-reporting helper with a Windows branch using GetProcessMemoryInfo from psapi.h (parallel to the existing __APPLE__ branch using mach_task_basic_info). Make <unistd.h> include non-Windows-only and add windows.h / psapi.h on Windows. Also: pass -lpsapi to 'zig cc' so GetProcessMemoryInfo links cleanly in the Windows job.
1 parent 15ec821 commit dd0f801

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
- name: Build C via zig cc
155155
shell: bash
156156
run: |
157-
zig cc -O3 -I. -o printable-binary-c.exe src/printable_binary.c
157+
zig cc -O3 -I. -o printable-binary-c.exe src/printable_binary.c -lpsapi
158158
159159
- name: Run Zig unit tests
160160
run: zig build test

src/printable_binary.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
#include <string.h>
1111
#include <stdint.h>
1212
#include <stdbool.h>
13+
#if defined(_WIN32)
14+
#include <windows.h>
15+
#include <psapi.h>
16+
#else
1317
#include <unistd.h>
18+
#endif
1419
#include <time.h>
1520
#if defined(__APPLE__)
1621
#include <mach/mach.h>
@@ -1633,6 +1638,10 @@ static long pb_rss_kb(void) {
16331638
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
16341639
if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count) != KERN_SUCCESS) return -1;
16351640
return (long)(info.resident_size / 1024);
1641+
#elif defined(_WIN32)
1642+
PROCESS_MEMORY_COUNTERS pmc;
1643+
if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) return -1;
1644+
return (long)(pmc.WorkingSetSize / 1024);
16361645
#else
16371646
FILE *f = fopen("/proc/self/statm", "r");
16381647
if (!f) return -1;

0 commit comments

Comments
 (0)