src/buffer.c

changeset 1292
1e7ee17777f4
parent 1291
5942859fd76c
--- a/src/buffer.c	Sun Apr 13 14:30:51 2025 +0200
+++ b/src/buffer.c	Sun Apr 13 14:56:05 2025 +0200
@@ -29,10 +29,27 @@
 #include "cx/buffer.h"
 
 #include <stdio.h>
-#include <unistd.h>
 #include <string.h>
 #include <errno.h>
 
+#ifdef _WIN32
+#include <Windows.h>
+#include <sysinfoapi.h>
+static unsigned long system_page_size() {
+    static unsigned long ps = 0;
+    if (ps == 0) {
+        SYSTEM_INFO sysinfo;
+        GetSystemInfo(&sysinfo);
+        ps = sysinfo.dwPageSize;
+    }
+    return ps;
+}
+#define SYSTEM_PAGE_SIZE system_page_size()
+#else
+#include <unistd.h>
+#define SYSTEM_PAGE_SIZE sysconf(_SC_PAGESIZE)
+#endif
+
 static int buffer_copy_on_write(CxBuffer* buffer) {
     if (0 == (buffer->flags & CX_BUFFER_COPY_ON_WRITE)) return 0;
     void *newspace = cxMalloc(buffer->allocator, buffer->capacity);
@@ -191,7 +208,7 @@
         return 0;
     }
 
-    unsigned long pagesize = sysconf(_SC_PAGESIZE);
+    unsigned long pagesize = SYSTEM_PAGE_SIZE;
     // if page size is larger than 64 KB - for some reason - truncate to 64 KB
     if (pagesize > 65536) pagesize = 65536;
     if (newcap < pagesize) {

mercurial