1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 05:27:45 +00:00

uptime, users, whoami: fix build

This commit is contained in:
Michael Gehring 2015-01-10 17:55:29 +01:00
parent 8cd7295a19
commit 8d889fc5c9
3 changed files with 11 additions and 16 deletions

View file

@ -17,6 +17,7 @@ extern crate getopts;
extern crate libc;
extern crate "time" as rtime;
use std::ffi::CString;
use std::mem::transmute;
use std::io::{print, File};
use std::ptr::null;
@ -105,11 +106,9 @@ fn print_loadavg() {
#[cfg(unix)]
fn process_utmpx() -> (Option<time_t>, uint) {
DEFAULT_FILE.with_c_str(|filename| {
unsafe {
utmpxname(filename);
}
});
unsafe {
utmpxname(CString::from_slice(DEFAULT_FILE.as_bytes()).as_ptr());
}
let mut nusers = 0;
let mut boot_time = None;
@ -172,7 +171,7 @@ fn get_uptime(boot_time: Option<time_t>) -> i64 {
_ => return match boot_time {
Some(t) => {
let now = rtime::get_time().sec;
let time = t.to_i64().unwrap();
let time = t as i64;
((now - time) * 100) as i64 // Return in ms
},
_ => -1

View file

@ -17,7 +17,7 @@
extern crate getopts;
extern crate libc;
use std::ffi::c_str_to_bytes;
use std::ffi::{CString, c_str_to_bytes};
use std::io::print;
use std::mem;
use std::ptr;
@ -89,11 +89,9 @@ pub fn uumain(args: Vec<String>) -> isize {
}
fn exec(filename: &str) {
filename.with_c_str(|filename| {
unsafe {
utmpxname(filename);
}
});
unsafe {
utmpxname(CString::from_slice(filename.as_bytes()).as_ptr());
}
let mut users = vec!();

View file

@ -35,9 +35,7 @@ mod platform {
let passwd: *const c_passwd = getpwuid(geteuid());
let pw_name: *const libc::c_char = (*passwd).pw_name;
let name = String::from_raw_buf(pw_name as *const u8);
name
String::from_utf8_lossy(::std::ffi::c_str_to_bytes(&pw_name)).to_string()
}
}
@ -56,7 +54,7 @@ mod platform {
if !GetUserNameA(buffer.as_mut_ptr(), &mut (buffer.len() as libc::uint32_t)) == 0 {
crash!(1, "username is too long");
}
String::from_raw_buf(buffer.as_ptr() as *const u8)
String::from_utf8_lossy(::std::ffi::c_str_to_bytes(&buffer.as_ptr())).to_string()
}
}