1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

hostname: fix sethostname prototype on linux

This commit is contained in:
Michael Gehring 2014-06-17 03:01:44 +02:00
parent f4615d746d
commit 8bbe123023

View file

@ -20,9 +20,18 @@ use getopts::{optflag, getopts, usage};
extern {
fn gethostname(name: *libc::c_char, namelen: libc::size_t) -> libc::c_int;
}
#[cfg(target_os = "macos")]
extern {
fn sethostname(name: *libc::c_char, namelen: libc::c_int) -> libc::c_int;
}
#[cfg(target_os = "linux")]
extern {
fn sethostname(name: *libc::c_char, namelen: libc::size_t) -> libc::c_int;
}
#[allow(dead_code)]
fn main () { os::set_exit_status(uumain(os::args())); }
@ -99,11 +108,25 @@ fn xgethostname() -> String {
str::from_utf8(name.slice_to(last_char)).unwrap().to_string()
}
#[cfg(target_os = "macos")]
fn xsethostname(name: &str) {
let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as i8).collect();
let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as libc::c_char).collect();
let err = unsafe {
sethostname (vec_name.as_ptr(), vec_name.len() as i32)
sethostname (vec_name.as_ptr(), vec_name.len() as libc::c_int)
};
if err != 0 {
println!("Cannot set hostname to {:s}", name);
}
}
#[cfg(target_os = "linux")]
fn xsethostname(name: &str) {
let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as libc::c_char).collect();
let err = unsafe {
sethostname (vec_name.as_ptr(), vec_name.len() as libc::size_t)
};
if err != 0 {