diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index ed1f5e89f0b775..97f45cd0950d3d 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -506,3 +506,10 @@ pub fn posix_set_permission_bit(path_s string, mode u32, enable bool) { fn get_long_path(path string) !string { return path } + +fn C.sysconf(name int) i64 + +// page_size returns the page size in bytes. +pub fn page_size() int { + return int(C.sysconf(C._SC_PAGESIZE)) +} diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index f424fac58772cc..74b71d7d5aa8e9 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -1012,3 +1012,7 @@ fn test_mv_by_cp_across_partitions() { fn test_mv_across_partitions() { move_across_partitions_using_function(os.mv)! } + +fn test_page_size() { + assert os.page_size() >= 4096 // this is normal and assumed. +} diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 75357f1db15558..8378148bf6809d 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -592,3 +592,19 @@ fn get_long_path(path string) !string { long_path := unsafe { string_from_wide(&long_path_buf[0]) } return long_path } + +// C.SYSTEM_INFO contains information about the current computer system. This includes the architecture and type of the processor, the number of processors in the system, the page size, and other such information. +[typedef] +pub struct C.SYSTEM_INFO { + dwNumberOfProcessors u32 + dwPageSize u32 +} + +fn C.GetSystemInfo(&C.SYSTEM_INFO) + +// page_size returns the page size in bytes. +pub fn page_size() int { + sinfo := C.SYSTEM_INFO{} + C.GetSystemInfo(&sinfo) + return int(sinfo.dwPageSize) +} diff --git a/vlib/runtime/runtime_windows.c.v b/vlib/runtime/runtime_windows.c.v index 12ecf9e61aba4b..4781dfb116e956 100644 --- a/vlib/runtime/runtime_windows.c.v +++ b/vlib/runtime/runtime_windows.c.v @@ -2,11 +2,6 @@ module runtime import os -[typedef] -pub struct C.SYSTEM_INFO { - dwNumberOfProcessors u32 -} - [typedef] pub struct C.MEMORYSTATUS { dwTotalPhys usize