mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
Merge pull request #257 from ebfe/hostname
hostname: fix sethostname prototype on linux
This commit is contained in:
commit
10fd43ab22
1 changed files with 25 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue