summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Cohn <raphael.cohn@stormmq.com>2016-05-13 11:18:34 +0100
committerRaphael Cohn <raphael.cohn@stormmq.com>2016-05-20 11:17:22 +0100
commite6150ae2b9629db81a48be8a60bd7b5b20aa1d46 (patch)
treedf2e58796edb4abb4708d2e050271b8637919dda
parent81e3af27ea10d2e4004dc510b22b7285c0627e55 (diff)
downloadrust-libc-e6150ae2b9629db81a48be8a60bd7b5b20aa1d46.tar.gz
Adding sysinfo() and sysinfo struct for Linux and Android.
Sadly, the sysinfo struct varies slightly between Musl and Glibc / Bionic. This means that users need to be careful when using the uptime, and should always cast it to a signed value. Why uptime can be signed is beyond me...
-rw-r--r--libc-test/build.rs1
-rw-r--r--src/unix/notbsd/android/b32.rs17
-rw-r--r--src/unix/notbsd/android/b64.rs17
-rw-r--r--src/unix/notbsd/linux/mips.rs17
-rw-r--r--src/unix/notbsd/linux/musl/mod.rs17
-rw-r--r--src/unix/notbsd/linux/other/b32/mod.rs17
-rw-r--r--src/unix/notbsd/linux/other/b64/mod.rs17
-rw-r--r--src/unix/notbsd/mod.rs3
8 files changed, 106 insertions, 0 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index a3626937ba..cdfe358488 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -163,6 +163,7 @@ fn main() {
cfg.header("sys/sendfile.h");
cfg.header("sys/vfs.h");
cfg.header("sys/syscall.h");
+ cfg.header("sys/sysinfo.h");
if !musl {
cfg.header("linux/netlink.h");
cfg.header("linux/magic.h");
diff --git a/src/unix/notbsd/android/b32.rs b/src/unix/notbsd/android/b32.rs
index 3a295cc720..0b1f8d2459 100644
--- a/src/unix/notbsd/android/b32.rs
+++ b/src/unix/notbsd/android/b32.rs
@@ -102,6 +102,23 @@ s! {
pub f_flags: ::uint32_t,
pub f_spare: [::uint32_t; 4],
}
+
+ pub struct sysinfo {
+ pub uptime: ::c_long,
+ pub loads: [::c_ulong; 3],
+ pub totalram: ::c_ulong,
+ pub freeram: ::c_ulong,
+ pub sharedram: ::c_ulong,
+ pub bufferram: ::c_ulong,
+ pub totalswap: ::c_ulong,
+ pub freeswap: ::c_ulong,
+ pub procs: ::c_ushort,
+ pub pad: ::c_ushort,
+ pub totalhigh: ::c_ulong,
+ pub freehigh: ::c_ulong,
+ pub mem_unit: ::c_uint,
+ pub _f: [::c_char; 8],
+ }
}
pub const SYS_gettid: ::c_long = 224;
diff --git a/src/unix/notbsd/android/b64.rs b/src/unix/notbsd/android/b64.rs
index 98b643f0b0..e9beff4478 100644
--- a/src/unix/notbsd/android/b64.rs
+++ b/src/unix/notbsd/android/b64.rs
@@ -112,6 +112,23 @@ s! {
pub f_flags: ::uint64_t,
pub f_spare: [::uint64_t; 4],
}
+
+ pub struct sysinfo {
+ pub uptime: ::c_long,
+ pub loads: [::c_ulong; 3],
+ pub totalram: ::c_ulong,
+ pub freeram: ::c_ulong,
+ pub sharedram: ::c_ulong,
+ pub bufferram: ::c_ulong,
+ pub totalswap: ::c_ulong,
+ pub freeswap: ::c_ulong,
+ pub procs: ::c_ushort,
+ pub pad: ::c_ushort,
+ pub totalhigh: ::c_ulong,
+ pub freehigh: ::c_ulong,
+ pub mem_unit: ::c_uint,
+ pub _f: [::c_char; 0],
+ }
}
pub const SYS_gettid: ::c_long = 178;
diff --git a/src/unix/notbsd/linux/mips.rs b/src/unix/notbsd/linux/mips.rs
index ae8725d503..11fa73718f 100644
--- a/src/unix/notbsd/linux/mips.rs
+++ b/src/unix/notbsd/linux/mips.rs
@@ -172,6 +172,23 @@ s! {
pub l_pid: ::pid_t,
pad: [::c_long; 4],
}
+
+ pub struct sysinfo {
+ pub uptime: ::c_long,
+ pub loads: [::c_ulong; 3],
+ pub totalram: ::c_ulong,
+ pub freeram: ::c_ulong,
+ pub sharedram: ::c_ulong,
+ pub bufferram: ::c_ulong,
+ pub totalswap: ::c_ulong,
+ pub freeswap: ::c_ulong,
+ pub procs: ::c_ushort,
+ pub pad: ::c_ushort,
+ pub totalhigh: ::c_ulong,
+ pub freehigh: ::c_ulong,
+ pub mem_unit: ::c_uint,
+ pub _f: [::c_char; 8],
+ }
}
pub const BUFSIZ: ::c_uint = 8192;
diff --git a/src/unix/notbsd/linux/musl/mod.rs b/src/unix/notbsd/linux/musl/mod.rs
index 631a39a493..7aeb31047e 100644
--- a/src/unix/notbsd/linux/musl/mod.rs
+++ b/src/unix/notbsd/linux/musl/mod.rs
@@ -56,6 +56,23 @@ s! {
pub l_len: ::off_t,
pub l_pid: ::pid_t,
}
+
+ pub struct sysinfo {
+ pub uptime: ::c_ulong,
+ pub loads: [::c_ulong; 3],
+ pub totalram: ::c_ulong,
+ pub freeram: ::c_ulong,
+ pub sharedram: ::c_ulong,
+ pub bufferram: ::c_ulong,
+ pub totalswap: ::c_ulong,
+ pub freeswap: ::c_ulong,
+ pub procs: ::c_ushort,
+ pub pad: ::c_ushort,
+ pub totalhigh: ::c_ulong,
+ pub freehigh: ::c_ulong,
+ pub mem_unit: ::c_uint,
+ pub __reserved: [::c_char; 256],
+ }
}
pub const BUFSIZ: ::c_uint = 1024;
diff --git a/src/unix/notbsd/linux/other/b32/mod.rs b/src/unix/notbsd/linux/other/b32/mod.rs
index b39ff683f6..afa8a8459c 100644
--- a/src/unix/notbsd/linux/other/b32/mod.rs
+++ b/src/unix/notbsd/linux/other/b32/mod.rs
@@ -66,6 +66,23 @@ s! {
pub struct sigset_t {
__val: [::c_ulong; 32],
}
+
+ pub struct sysinfo {
+ pub uptime: ::c_long,
+ pub loads: [::c_ulong; 3],
+ pub totalram: ::c_ulong,
+ pub freeram: ::c_ulong,
+ pub sharedram: ::c_ulong,
+ pub bufferram: ::c_ulong,
+ pub totalswap: ::c_ulong,
+ pub freeswap: ::c_ulong,
+ pub procs: ::c_ushort,
+ pub pad: ::c_ushort,
+ pub totalhigh: ::c_ulong,
+ pub freehigh: ::c_ulong,
+ pub mem_unit: ::c_uint,
+ pub _f: [::c_char; 8],
+ }
}
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
diff --git a/src/unix/notbsd/linux/other/b64/mod.rs b/src/unix/notbsd/linux/other/b64/mod.rs
index 663b09333c..ccf99881f7 100644
--- a/src/unix/notbsd/linux/other/b64/mod.rs
+++ b/src/unix/notbsd/linux/other/b64/mod.rs
@@ -14,6 +14,23 @@ s! {
pub struct sigset_t {
__val: [::c_ulong; 16],
}
+
+ pub struct sysinfo {
+ pub uptime: ::c_long,
+ pub loads: [::c_ulong; 3],
+ pub totalram: ::c_ulong,
+ pub freeram: ::c_ulong,
+ pub sharedram: ::c_ulong,
+ pub bufferram: ::c_ulong,
+ pub totalswap: ::c_ulong,
+ pub freeswap: ::c_ulong,
+ pub procs: ::c_ushort,
+ pub pad: ::c_ushort,
+ pub totalhigh: ::c_ulong,
+ pub freehigh: ::c_ulong,
+ pub mem_unit: ::c_uint,
+ pub _f: [::c_char; 0],
+ }
}
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs
index 94868d8a43..d94ce78354 100644
--- a/src/unix/notbsd/mod.rs
+++ b/src/unix/notbsd/mod.rs
@@ -652,6 +652,8 @@ pub const LOG_PERROR: ::c_int = 0x20;
pub const PIPE_BUF: usize = 4096;
+pub const SI_LOAD_SHIFT: ::c_uint = 16;
+
f! {
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
@@ -800,6 +802,7 @@ extern {
pub fn setrlimit64(resource: ::c_int, rlim: *const rlimit64) -> ::c_int;
pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
+ pub fn sysinfo (info: *mut ::sysinfo) -> ::c_int;
}
cfg_if! {