From 31111ac1990940245387293e94d20bd04d861525 Mon Sep 17 00:00:00 2001 From: Arcterus Date: Fri, 28 Nov 2014 14:49:22 -0800 Subject: [PATCH] Fix most deprecation warnings and remove hacky nohup code --- src/base64/base64.rs | 2 +- src/chroot/chroot.rs | 8 +++---- src/common/c_types.rs | 7 +++--- src/fmt/linebreak.rs | 2 +- src/hashsum/hashsum.rs | 10 ++++---- src/id/id.rs | 49 ++++++++++++++++++++-------------------- src/logname/logname.rs | 3 +-- src/nohup/nohup.rs | 45 +++++++++--------------------------- src/truncate/truncate.rs | 4 ++-- src/tty/tty.rs | 3 +-- src/uname/uname.rs | 11 ++++----- src/uptime/uptime.rs | 38 ++++++++++++++++++++----------- src/users/users.rs | 3 +-- src/whoami/whoami.rs | 6 ++--- 14 files changed, 86 insertions(+), 105 deletions(-) diff --git a/src/base64/base64.rs b/src/base64/base64.rs index 18c82823e..5ec400149 100644 --- a/src/base64/base64.rs +++ b/src/base64/base64.rs @@ -106,7 +106,7 @@ fn decode(input: &mut Reader, ignore_garbage: bool) { to_decode.as_slice() .trim_chars(|c: char| { let num = match c.to_ascii_opt() { - Some(ascii) => ascii.to_byte(), + Some(ascii) => ascii.as_byte(), None => return false }; !(num >= 'a' as u8 && num <= 'z' as u8 || diff --git a/src/chroot/chroot.rs b/src/chroot/chroot.rs index eb3c63913..5afbbfa99 100644 --- a/src/chroot/chroot.rs +++ b/src/chroot/chroot.rs @@ -92,8 +92,8 @@ pub fn uumain(args: Vec) -> int { set_context(&newroot, &opts); unsafe { - let executable = command[0].as_slice().to_c_str().unwrap(); - let mut command_parts: Vec<*const i8> = command.iter().map(|x| x.to_c_str().unwrap()).collect(); + let executable = command[0].as_slice().to_c_str().into_inner(); + let mut command_parts: Vec<*const i8> = command.iter().map(|x| x.to_c_str().into_inner()).collect(); command_parts.push(std::ptr::null()); execvp(executable as *const libc::c_char, command_parts.as_ptr() as *mut *const libc::c_char) as int } @@ -128,7 +128,7 @@ fn enter_chroot(root: &Path) { let root_str = root.display(); std::os::change_dir(root).unwrap(); let err = unsafe { - chroot(".".to_c_str().unwrap() as *const libc::c_char) + chroot(".".to_c_str().into_inner() as *const libc::c_char) }; if err != 0 { crash!(1, "cannot chroot to {}: {}", root_str, strerror(err).as_slice()) @@ -193,7 +193,7 @@ fn set_user(user: &str) { fn strerror(errno: i32) -> String { unsafe { let err = libc::funcs::c95::string::strerror(errno); - std::string::raw::from_buf(err as *const u8) + String::from_raw_buf(err as *const u8) } } diff --git a/src/common/c_types.rs b/src/common/c_types.rs index 93be7ec71..ae2580922 100644 --- a/src/common/c_types.rs +++ b/src/common/c_types.rs @@ -19,7 +19,6 @@ use std::vec::Vec; use std::os; use std::ptr::{null_mut, read}; -use std::string::raw::from_buf; #[cfg(any(target_os = "macos", target_os = "freebsd"))] #[repr(C)] @@ -124,7 +123,7 @@ pub fn get_pw_from_args(free: &Vec) -> Option { // Passed the username as a string } else { let pw_pointer = unsafe { - getpwnam(username.as_slice().to_c_str().unwrap() as *const libc::c_char) + getpwnam(username.as_slice().to_c_str().into_inner() as *const libc::c_char) }; if pw_pointer.is_not_null() { Some(unsafe { read(pw_pointer) }) @@ -141,7 +140,7 @@ pub fn get_group(groupname: &str) -> Option { let group = if groupname.chars().all(|c| c.is_digit(10)) { unsafe { getgrgid(from_str::(groupname).unwrap()) } } else { - unsafe { getgrnam(groupname.to_c_str().unwrap() as *const c_char) } + unsafe { getgrnam(groupname.to_c_str().into_inner() as *const c_char) } }; if group.is_not_null() { @@ -217,7 +216,7 @@ pub fn group(possible_pw: Option, nflag: bool) { let group = unsafe { getgrgid(g) }; if group.is_not_null() { let name = unsafe { - from_buf(read(group).gr_name as *const u8) + String::from_raw_buf(read(group).gr_name as *const u8) }; print!("{} ", name); } diff --git a/src/fmt/linebreak.rs b/src/fmt/linebreak.rs index 7ba4c73bf..fc0214e56 100644 --- a/src/fmt/linebreak.rs +++ b/src/fmt/linebreak.rs @@ -94,7 +94,7 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box>>(mut iter: T, args: &mut BreakArgs<'a>) { +fn break_simple<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &mut BreakArgs<'a>) { iter.fold((args.init_len, false), |l, winfo| accum_words_simple(args, l, winfo)); silent_unwrap!(args.ostream.write_char('\n')); } diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index 7d649d71e..fb6582039 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -212,10 +212,10 @@ fn hashsum(algoname: &str, mut digest: Box, files: Vec, binary: let mut buffer = file; for (i, line) in buffer.lines().enumerate() { let line = safe_unwrap!(line); - let (ck_filename, sum, binary_check) = match gnu_re.captures(line.as_slice()) { - Some(caps) => (caps.name("fileName"), caps.name("digest").to_ascii().to_lowercase(), caps.name("binary") == "*"), + let (ck_filename, sum, binary_check): (_, Vec, _) = match gnu_re.captures(line.as_slice()) { + Some(caps) => (caps.name("fileName"), caps.name("digest").to_ascii().iter().map(|ch| ch.to_lowercase()).collect(), caps.name("binary") == "*"), None => match bsd_re.captures(line.as_slice()) { - Some(caps) => (caps.name("fileName"), caps.name("digest").to_ascii().to_lowercase(), true), + Some(caps) => (caps.name("fileName"), caps.name("digest").to_ascii().iter().map(|ch| ch.to_lowercase()).collect(), true), None => { bad_format += 1; if strict { @@ -228,8 +228,8 @@ fn hashsum(algoname: &str, mut digest: Box, files: Vec, binary: } } }; - let real_sum = safe_unwrap!(digest_reader(&mut digest, &mut safe_unwrap!(File::open(&Path::new(ck_filename))), binary_check)) - .as_slice().to_ascii().to_lowercase(); + let real_sum: Vec = safe_unwrap!(digest_reader(&mut digest, &mut safe_unwrap!(File::open(&Path::new(ck_filename))), binary_check)) + .as_slice().to_ascii().iter().map(|ch| ch.to_lowercase()).collect(); if sum.as_slice() == real_sum.as_slice() { if !quiet { pipe_println!("{}: OK", ck_filename); diff --git a/src/id/id.rs b/src/id/id.rs index f43c876be..1c160129e 100644 --- a/src/id/id.rs +++ b/src/id/id.rs @@ -25,7 +25,6 @@ use libc::{ getuid }; use libc::funcs::posix88::unistd::{getegid, geteuid, getlogin}; -use std::string::raw::from_buf; use getopts::{getopts, optflag, usage}; use c_types::{ c_passwd, @@ -139,7 +138,7 @@ pub fn uumain(args: Vec) -> int { let gr = unsafe { getgrgid(id) }; if nflag && gr.is_not_null() { - let gr_name = unsafe { from_buf(read(gr).gr_name as *const u8) }; + let gr_name = unsafe { String::from_raw_buf(read(gr).gr_name as *const u8) }; println!("{}", gr_name); } else { println!("{}", id); @@ -159,7 +158,7 @@ pub fn uumain(args: Vec) -> int { let pw = unsafe { getpwuid(id) }; if nflag && pw.is_not_null() { let pw_name = unsafe { - from_buf(read(pw).pw_name as *const u8) + String::from_raw_buf(read(pw).pw_name as *const u8) }; println!("{}", pw_name); } else { @@ -197,16 +196,16 @@ fn pretty(possible_pw: Option) { if possible_pw.is_some() { let pw = possible_pw.unwrap(); - let pw_name = unsafe { from_buf(pw.pw_name as *const u8) }; + let pw_name = unsafe { String::from_raw_buf(pw.pw_name as *const u8) }; print!("uid\t{}\ngroups\t", pw_name); group(possible_pw, true); } else { - let login = unsafe { from_buf(getlogin() as *const u8) }; + let login = unsafe { String::from_raw_buf(getlogin() as *const u8) }; let rid = unsafe { getuid() }; let pw = unsafe { getpwuid(rid) }; let is_same_user = unsafe { - from_buf(read(pw).pw_name as *const u8) == login + String::from_raw_buf(read(pw).pw_name as *const u8) == login }; if pw.is_null() || is_same_user { @@ -216,7 +215,7 @@ fn pretty(possible_pw: Option) { if pw.is_not_null() { println!( "uid\t{}", - unsafe { from_buf(read(pw).pw_name as *const u8) }) + unsafe { String::from_raw_buf(read(pw).pw_name as *const u8) }) } else { println!("uid\t{}\n", rid); } @@ -227,7 +226,7 @@ fn pretty(possible_pw: Option) { if pw.is_not_null() { println!( "euid\t{}", - unsafe { from_buf(read(pw).pw_name as *const u8) }); + unsafe { String::from_raw_buf(read(pw).pw_name as *const u8) }); } else { println!("euid\t{}", eid); } @@ -240,7 +239,7 @@ fn pretty(possible_pw: Option) { if gr.is_not_null() { println!( "rgid\t{}", - unsafe { from_buf(read(gr).gr_name as *const u8) }); + unsafe { String::from_raw_buf(read(gr).gr_name as *const u8) }); } else { println!("rgid\t{}", rid); } @@ -259,12 +258,12 @@ fn pline(possible_pw: Option) { possible_pw.unwrap() }; - let pw_name = unsafe { from_buf(pw.pw_name as *const u8) }; - let pw_passwd = unsafe { from_buf(pw.pw_passwd as *const u8) }; - let pw_class = unsafe { from_buf(pw.pw_class as *const u8) }; - let pw_gecos = unsafe { from_buf(pw.pw_gecos as *const u8) }; - let pw_dir = unsafe { from_buf(pw.pw_dir as *const u8) }; - let pw_shell = unsafe { from_buf(pw.pw_shell as *const u8) }; + let pw_name = unsafe { String::from_raw_buf(pw.pw_name as *const u8) }; + let pw_passwd = unsafe { String::from_raw_buf(pw.pw_passwd as *const u8) }; + let pw_class = unsafe { String::from_raw_buf(pw.pw_class as *const u8) }; + let pw_gecos = unsafe { String::from_raw_buf(pw.pw_gecos as *const u8) }; + let pw_dir = unsafe { String::from_raw_buf(pw.pw_dir as *const u8) }; + let pw_shell = unsafe { String::from_raw_buf(pw.pw_shell as *const u8) }; println!( "{}:{}:{}:{}:{}:{}:{}:{}:{}:{}", @@ -288,11 +287,11 @@ fn pline(possible_pw: Option) { possible_pw.unwrap() }; - let pw_name = unsafe { from_buf(pw.pw_name as *const u8)}; - let pw_passwd = unsafe { from_buf(pw.pw_passwd as *const u8)}; - let pw_gecos = unsafe { from_buf(pw.pw_gecos as *const u8)}; - let pw_dir = unsafe { from_buf(pw.pw_dir as *const u8)}; - let pw_shell = unsafe { from_buf(pw.pw_shell as *const u8)}; + let pw_name = unsafe { String::from_raw_buf(pw.pw_name as *const u8)}; + let pw_passwd = unsafe { String::from_raw_buf(pw.pw_passwd as *const u8)}; + let pw_gecos = unsafe { String::from_raw_buf(pw.pw_gecos as *const u8)}; + let pw_dir = unsafe { String::from_raw_buf(pw.pw_dir as *const u8)}; + let pw_shell = unsafe { String::from_raw_buf(pw.pw_shell as *const u8)}; println!( "{}:{}:{}:{}:{}:{}:{}", @@ -352,7 +351,7 @@ fn id_print(possible_pw: Option, print!( "uid={}({})", uid, - unsafe { from_buf(possible_pw.unwrap().pw_name as *const u8) }); + unsafe { String::from_raw_buf(possible_pw.unwrap().pw_name as *const u8) }); } else { print!("uid={}", unsafe { getuid() }); } @@ -362,7 +361,7 @@ fn id_print(possible_pw: Option, if gr.is_not_null() { print!( "({})", - unsafe { from_buf(read(gr).gr_name as *const u8) }); + unsafe { String::from_raw_buf(read(gr).gr_name as *const u8) }); } let euid = unsafe { geteuid() }; @@ -372,7 +371,7 @@ fn id_print(possible_pw: Option, if pw.is_not_null() { print!( "({})", - unsafe { from_buf(read(pw).pw_name as *const u8) }); + unsafe { String::from_raw_buf(read(pw).pw_name as *const u8) }); } } @@ -382,7 +381,7 @@ fn id_print(possible_pw: Option, unsafe { let grp = getgrgid(egid); if grp.is_not_null() { - print!("({})", from_buf(read(grp).gr_name as *const u8)); + print!("({})", String::from_raw_buf(read(grp).gr_name as *const u8)); } } } @@ -397,7 +396,7 @@ fn id_print(possible_pw: Option, let group = unsafe { getgrgid(gr) }; if group.is_not_null() { let name = unsafe { - from_buf(read(group).gr_name as *const u8) + String::from_raw_buf(read(group).gr_name as *const u8) }; print!("({})", name); } diff --git a/src/logname/logname.rs b/src/logname/logname.rs index 5ab75574b..4c4704181 100644 --- a/src/logname/logname.rs +++ b/src/logname/logname.rs @@ -19,7 +19,6 @@ extern crate getopts; extern crate libc; use std::io::print; -use std::string; use libc::c_char; #[path = "../common/util.rs"] mod util; @@ -32,7 +31,7 @@ extern { unsafe fn get_userlogin() -> String { let login: *const libc::c_char = getlogin(); - string::raw::from_buf(login as *const u8) + String::from_raw_buf(login as *const u8) } static NAME: &'static str = "logname"; diff --git a/src/nohup/nohup.rs b/src/nohup/nohup.rs index e044d4234..d0ce46b02 100644 --- a/src/nohup/nohup.rs +++ b/src/nohup/nohup.rs @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -#![feature(macro_rules)] +#![feature(globs, macro_rules)] extern crate getopts; extern crate libc; use getopts::{optflag, getopts, usage}; use std::io::stdio::{stdin_raw, stdout_raw, stderr_raw}; use std::io::{File, Open, Read, Append, Write}; +use std::os::unix::prelude::*; use libc::funcs::posix88::unistd::{dup2, execvp}; use libc::consts::os::posix88::SIGHUP; use libc::funcs::posix01::signal::signal; @@ -32,35 +33,11 @@ extern { fn _vprocmgr_detach_from_console(flags: u32) -> *const libc::c_int; } -// BEGIN CODE TO DELETE AFTER https://github.com/rust-lang/rust/issues/18897 is fixed -struct HackyFile { - pub fd: FileDesc, - path: Path, - last_nread: int -} - -struct FileDesc { - fd: libc::c_int, - close_on_drop: bool -} - -trait AsFileDesc { - fn as_fd(&self) -> FileDesc; -} - -impl AsFileDesc for File { - fn as_fd(&self) -> FileDesc { - let hack: HackyFile = unsafe { std::mem::transmute_copy(self) }; - hack.fd - } -} -// END CODE TO DELETE - #[cfg(target_os = "macos")] -fn rewind_stdout(s: &mut FileDesc) { +fn rewind_stdout(s: Fd) { match s.seek(0, io::SeekEnd) { Ok(_) => {} - Err(f) => crash!(1, "{}", f.detail.unwrap()) + Err(f) => crash!(1, "{}", f.detail.into_inner()) } } @@ -68,7 +45,7 @@ fn rewind_stdout(s: &mut FileDesc) { unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() } #[cfg(any(target_os = "linux", target_os = "freebsd"))] -fn rewind_stdout(_: &mut FileDesc) {} +fn rewind_stdout(_: Fd) {} pub fn uumain(args: Vec) -> int { let program = &args[0]; @@ -103,8 +80,8 @@ pub fn uumain(args: Vec) -> int { unsafe { // we ignore the memory leak here because it doesn't matter anymore - let executable = opts.free[0].as_slice().to_c_str().unwrap(); - let mut args: Vec<*const i8> = opts.free.iter().map(|x| x.to_c_str().unwrap()).collect(); + let executable = opts.free[0].as_slice().to_c_str().into_inner(); + let mut args: Vec<*const i8> = opts.free.iter().map(|x| x.to_c_str().into_inner()).collect(); args.push(std::ptr::null()); execvp(executable as *const libc::c_char, args.as_ptr() as *mut *const libc::c_char) as int } @@ -122,18 +99,18 @@ fn replace_fds() { crash!(2, "Cannot replace STDIN: {}", e) } }; - if unsafe { dup2(new_stdin.as_fd().fd, 0) } != 0 { + if unsafe { dup2(new_stdin.as_raw_fd(), 0) } != 0 { crash!(2, "Cannot replace STDIN: {}", std::io::IoError::last_error()) } } if replace_stdout { let new_stdout = find_stdout(); - let mut fd = new_stdout.as_fd(); + let fd = new_stdout.as_raw_fd(); - rewind_stdout(&mut fd); + rewind_stdout(fd); - if unsafe { dup2(fd.fd, 1) } != 1 { + if unsafe { dup2(fd, 1) } != 1 { crash!(2, "Cannot replace STDOUT: {}", std::io::IoError::last_error()) } } diff --git a/src/truncate/truncate.rs b/src/truncate/truncate.rs index 9637043fe..2cc6983d8 100644 --- a/src/truncate/truncate.rs +++ b/src/truncate/truncate.rs @@ -191,8 +191,8 @@ fn parse_size(size: &str) -> (u64, TruncateMode) { } }; if size.char_at(size.len() - 1).is_alphabetic() { - number *= match size.char_at(size.len() - 1).to_ascii().to_uppercase().to_char() { - 'B' => match size.char_at(size.len() - 2).to_ascii().to_uppercase().to_char() { + number *= match size.char_at(size.len() - 1).to_ascii().to_uppercase().as_char() { + 'B' => match size.char_at(size.len() - 2).to_ascii().to_uppercase().as_char() { 'K' => 1000, 'M' => 1000 * 1000, 'G' => 1000 * 1000 * 1000, diff --git a/src/tty/tty.rs b/src/tty/tty.rs index 2c10ba34a..4b63c88f4 100644 --- a/src/tty/tty.rs +++ b/src/tty/tty.rs @@ -19,7 +19,6 @@ extern crate getopts; extern crate libc; -use std::string; use std::io::println; use std::io::stdio::stderr; use getopts::{optflag,getopts}; @@ -50,7 +49,7 @@ pub fn uumain(args: Vec) -> int { } }; - let tty = unsafe { string::raw::from_buf(ttyname(libc::STDIN_FILENO) as *const u8) }; + let tty = unsafe { String::from_raw_buf(ttyname(libc::STDIN_FILENO) as *const u8) }; if !silent { if !tty.as_slice().is_whitespace() { diff --git a/src/uname/uname.rs b/src/uname/uname.rs index 168b21d9d..9772f8034 100644 --- a/src/uname/uname.rs +++ b/src/uname/uname.rs @@ -19,7 +19,6 @@ extern crate libc; use std::mem::uninitialized; use std::io::print; -use std::string::raw::from_buf; use c_types::utsname; #[path = "../common/util.rs"] mod util; @@ -41,11 +40,11 @@ unsafe fn getuname() -> utsrust { let mut uts: utsname = uninitialized(); uname(&mut uts); utsrust { - sysname: from_buf(uts.sysname.as_ptr() as *const u8), - nodename: from_buf(uts.nodename.as_ptr() as *const u8), - release: from_buf(uts.release.as_ptr() as *const u8), - version: from_buf(uts.version.as_ptr() as *const u8), - machine: from_buf(uts.machine.as_ptr() as *const u8) + sysname: String::from_raw_buf(uts.sysname.as_ptr() as *const u8), + nodename: String::from_raw_buf(uts.nodename.as_ptr() as *const u8), + release: String::from_raw_buf(uts.release.as_ptr() as *const u8), + version: String::from_raw_buf(uts.version.as_ptr() as *const u8), + machine: String::from_raw_buf(uts.machine.as_ptr() as *const u8) } } diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index 488c27543..0b500904d 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -16,13 +16,13 @@ extern crate getopts; extern crate libc; +extern crate "time" as rtime; use std::mem::transmute; use std::io::{print, File}; -use std::ptr::{null_mut, null}; +use std::ptr::null; use std::str::from_str; use libc::{time_t, c_double, c_int, c_char}; -use c_types::c_tm; use utmpx::*; #[path = "../common/util.rs"] mod util; @@ -33,10 +33,8 @@ use utmpx::*; static NAME: &'static str = "uptime"; +#[cfg(unix)] extern { - fn time(timep: *mut time_t) -> time_t; - fn localtime(timep: *const time_t) -> *const c_tm; - fn getloadavg(loadavg: *mut c_double, nelem: c_int) -> c_int; fn getutxent() -> *const c_utmp; @@ -47,6 +45,11 @@ extern { fn utmpxname(file: *const c_char) -> c_int; } +#[cfg(windows)] +extern { + fn GetTickCount() -> libc::uint32_t; +} + #[cfg(target_os = "freebsd")] unsafe extern fn utmpxname(_file: *const c_char) -> c_int { 0 @@ -102,6 +105,7 @@ fn print_loadavg() { } } +#[cfg(unix)] fn process_utmpx() -> (Option, uint) { DEFAULT_FILE.with_c_str(|filename| { unsafe { @@ -140,6 +144,11 @@ fn process_utmpx() -> (Option, uint) { (boot_time, nusers) } +#[cfg(windows)] +fn process_utmpx() -> (Option, uint) { + (None, 0) // TODO: change 0 to number of users +} + fn print_nusers(nusers: uint) { if nusers == 1 { print!("1 user, "); @@ -149,15 +158,13 @@ fn print_nusers(nusers: uint) { } fn print_time() { - let local_time = unsafe { *localtime(&time(null_mut())) }; + let local_time = rtime::now(); - if local_time.tm_hour >= 0 && local_time.tm_min >= 0 && - local_time.tm_sec >= 0 { - print!(" {:02}:{:02}:{:02} ", local_time.tm_hour, - local_time.tm_min, local_time.tm_sec); - } + print!(" {:02}:{:02}:{:02} ", local_time.tm_hour, + local_time.tm_min, local_time.tm_sec); } +#[cfg(unix)] fn get_uptime(boot_time: Option) -> i64 { let proc_uptime = File::open(&Path::new("/proc/uptime")) .read_to_string(); @@ -166,7 +173,7 @@ fn get_uptime(boot_time: Option) -> i64 { Ok(s) => s, _ => return match boot_time { Some(t) => { - let now = unsafe { time(null_mut()) }; + let now = rtime::get_time().sec; ((now - t) * 100) as i64 // Return in ms }, _ => -1 @@ -174,7 +181,7 @@ fn get_uptime(boot_time: Option) -> i64 { }; match uptime_text.as_slice().words().next() { - Some(s) => match from_str(s.replace(".","").as_slice()) { + Some(s) => match from_str(s.replace(".", "").as_slice()) { Some(n) => n, None => -1 }, @@ -182,6 +189,11 @@ fn get_uptime(boot_time: Option) -> i64 { } } +#[cfg(windows)] +fn get_uptime(boot_time: Option) -> i64 { + unsafe { GetTickCount() as i64 } +} + fn print_uptime(upsecs: i64) { let updays = upsecs / 86400; let uphours = (upsecs - (updays * 86400)) / 3600; diff --git a/src/users/users.rs b/src/users/users.rs index 8994e9e1f..74857fad8 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -22,7 +22,6 @@ extern crate libc; use std::io::print; use std::mem; use std::ptr; -use std::string; use utmpx::*; #[path = "../common/util.rs"] @@ -109,7 +108,7 @@ fn exec(filename: &str) { } if (*line).ut_type == USER_PROCESS { - let user = string::raw::from_buf(mem::transmute(&(*line).ut_user)); + let user = String::from_raw_buf(mem::transmute(&(*line).ut_user)); users.push(user); } } diff --git a/src/whoami/whoami.rs b/src/whoami/whoami.rs index a353eb25d..97f4b9bb9 100644 --- a/src/whoami/whoami.rs +++ b/src/whoami/whoami.rs @@ -25,7 +25,6 @@ use std::io::print; #[cfg(unix)] mod platform { use super::libc; - use std::string; use self::c_types::{c_passwd, getpwuid}; #[path = "../../common/c_types.rs"] mod c_types; @@ -38,7 +37,7 @@ mod platform { let passwd: *const c_passwd = getpwuid(geteuid()); let pw_name: *const libc::c_char = (*passwd).pw_name; - let name = string::raw::from_buf(pw_name as *const u8); + let name = String::from_raw_buf(pw_name as *const u8); name } @@ -48,7 +47,6 @@ mod platform { mod platform { pub use super::libc; use std::mem; - use std::string; extern "system" { pub fn GetUserNameA(out: *mut libc::c_char, len: *mut libc::uint32_t) -> libc::uint8_t; @@ -60,7 +58,7 @@ mod platform { if !GetUserNameA(buffer.as_mut_ptr(), &mut (buffer.len() as libc::uint32_t)) == 0 { crash!(1, "username is too long"); } - string::raw::from_buf(buffer.as_ptr() as *const u8) + String::from_raw_buf(buffer.as_ptr() as *const u8) } }