use crate::io;
pub fn dnsdomainname(_argc: i32, _argv: *const *const u8) -> i32 {
let mut buf = [0u8; 256];
if unsafe { libc::gethostname(buf.as_mut_ptr() as *mut i8, buf.len()) } != 0 {
return 1;
}
let len = buf.iter().position(|&c| c == 0).unwrap_or(buf.len());
if let Some(dot_pos) = buf[..len].iter().position(|&c| c == b'.') {
if dot_pos + 1 < len {
io::write_all(1, &buf[dot_pos + 1..len]);
io::write_str(1, b"\n");
}
}
0
}
#[cfg(test)]
mod tests {
extern crate std;
use std::process::Command;
use std::path::PathBuf;
fn get_armybox_path() -> PathBuf {
if let Ok(path) = std::env::var("ARMYBOX_PATH") {
return PathBuf::from(path);
}
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| std::env::current_dir().unwrap());
let release = manifest_dir.join("target/release/armybox");
if release.exists() { return release; }
manifest_dir.join("target/debug/armybox")
}
#[test]
fn test_dnsdomainname_runs() {
let armybox = get_armybox_path();
if !armybox.exists() { return; }
let output = Command::new(&armybox)
.args(["dnsdomainname"])
.output()
.unwrap();
assert_eq!(output.status.code(), Some(0));
}
}