From 2e260a6b298c1961370d3a5584d6b53f629a9505 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Sun, 13 Jan 2019 19:48:06 -0700
Subject: [PATCH] Add _SC_PAGE_SIZE, use sysconf to provide getpagesize

---
 src/header/unistd/mod.rs     | 2 +-
 src/header/unistd/sysconf.rs | 1 +
 src/platform/linux/mod.rs    | 5 -----
 src/platform/pal/mod.rs      | 2 --
 src/platform/redox/mod.rs    | 4 ----
 5 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs
index 0b0ac1af..998970da 100644
--- a/src/header/unistd/mod.rs
+++ b/src/header/unistd/mod.rs
@@ -332,7 +332,7 @@ pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int {
 
 #[no_mangle]
 pub extern "C" fn getpagesize() -> c_int {
-    Sys::getpagesize()
+    sysconf(_SC_PAGESIZE) as c_int
 }
 
 // #[no_mangle]
diff --git a/src/header/unistd/sysconf.rs b/src/header/unistd/sysconf.rs
index 8ce05f53..70f7694f 100644
--- a/src/header/unistd/sysconf.rs
+++ b/src/header/unistd/sysconf.rs
@@ -13,6 +13,7 @@ pub const _SC_TZNAME_MAX: c_int = 6;
 // ...
 pub const _SC_VERSION: c_int = 29;
 pub const _SC_PAGESIZE: c_int = 30;
+pub const _SC_PAGE_SIZE: c_int = 30;
 // ...
 pub const _SC_RE_DUP_MAX: c_int = 44;
 // ...
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index 68419a6e..5a42cda8 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -237,11 +237,6 @@ impl Pal for Sys {
         e(unsafe { syscall!(GETGID) }) as gid_t
     }
 
-    fn getpagesize() -> c_int {
-        //TODO
-        4096
-    }
-
     fn getpgid(pid: pid_t) -> pid_t {
         e(unsafe { syscall!(GETPGID, pid) }) as pid_t
     }
diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs
index a67a2906..bae5380a 100644
--- a/src/platform/pal/mod.rs
+++ b/src/platform/pal/mod.rs
@@ -75,8 +75,6 @@ pub trait Pal {
 
     fn getgid() -> gid_t;
 
-    fn getpagesize() -> c_int;
-
     fn getpgid(pid: pid_t) -> pid_t;
 
     fn getpid() -> pid_t;
diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs
index 0a96db2d..44233a8b 100644
--- a/src/platform/redox/mod.rs
+++ b/src/platform/redox/mod.rs
@@ -534,10 +534,6 @@ impl Pal for Sys {
         e(syscall::getgid()) as gid_t
     }
 
-    fn getpagesize() -> c_int {
-        4096
-    }
-
     fn getpgid(pid: pid_t) -> pid_t {
         e(syscall::getpgid(pid as usize)) as pid_t
     }
-- 
GitLab