Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Fix misc issues on BSD (#79)
Browse files Browse the repository at this point in the history
Fix misc issues on BSD
  • Loading branch information
Phate6660 committed Jan 27, 2020
2 parents 154b65a + b656e21 commit 2bd3ef9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/memory.rs
Expand Up @@ -74,12 +74,15 @@ impl RAMInfo {
self.used = Some(used / 1024_f64 / 1024_f64);
self.total = Some(total / 1024_f64 / 1024_f64);
return Ok(());
} else if os == &OS::FreeBSD || os == &OS::Other {
} else if os == &OS::FreeBSD || os == &OS::DragonflyBSD {
let mut buffer = String::new();
Command::new("sysctl").arg("-n").arg("hw.physmem")
.output().context(RAMErr)?.stdout.iter()
.for_each(|b| buffer.push(*b as char));
total = buffer.parse::<f64>().unwrap();

// remove non-integer chars from buffer
buffer = buffer.trim().replace("\n", "");
total = buffer.parse::<u64>().unwrap() as f64;

let pagesize: f64;
let inactive: f64;
Expand Down
12 changes: 7 additions & 5 deletions src/util.rs
Expand Up @@ -8,6 +8,7 @@ pub enum OS {
FreeBSD,
OpenBSD,
NetBSD,
DragonflyBSD,
Other
}

Expand All @@ -23,11 +24,12 @@ impl OSInfo {
.output()?.stdout.iter()
.for_each(|b| uname.push(*b as char));
let os = match uname.replace("\n", "").trim().as_ref() {
"Linux" => OS::Linux,
"FreeBSD" => OS::FreeBSD,
"NetBSD" => OS::NetBSD,
"OpenBSD" => OS::OpenBSD,
&_ => OS::Other,
"Linux" => OS::Linux,
"FreeBSD" => OS::FreeBSD,
"NetBSD" => OS::NetBSD,
"OpenBSD" => OS::OpenBSD,
"DragonFly" => OS::DragonflyBSD,
&_ => OS::Other,
};

Ok(os)
Expand Down

0 comments on commit 2bd3ef9

Please sign in to comment.