diff --git a/chroot/chroot.rs b/chroot/chroot.rs index 5d22cdccb..dfd6177ff 100644 --- a/chroot/chroot.rs +++ b/chroot/chroot.rs @@ -20,17 +20,17 @@ use libc::funcs::posix88::unistd::{execvp, setuid, setgid}; #[path = "../common/c_types.rs"] mod c_types; extern { - fn chroot(path: *libc::c_char) -> libc::c_int; + fn chroot(path: *const libc::c_char) -> libc::c_int; } #[cfg(target_os = "macos")] extern { - fn setgroups(size: libc::c_int, list: *libc::gid_t) -> libc::c_int; + fn setgroups(size: libc::c_int, list: *const libc::gid_t) -> libc::c_int; } #[cfg(target_os = "linux")] extern { - fn setgroups(size: libc::size_t, list: *libc::gid_t) -> libc::c_int; + fn setgroups(size: libc::size_t, list: *const libc::gid_t) -> libc::c_int; } static NAME: &'static str = "chroot"; @@ -92,9 +92,9 @@ pub fn uumain(args: Vec) -> int { unsafe { let executable = command.get(0).as_slice().to_c_str().unwrap(); - let mut commandParts: Vec<*i8> = command.iter().map(|x| x.to_c_str().unwrap()).collect(); + let mut commandParts: Vec<*const i8> = command.iter().map(|x| x.to_c_str().unwrap()).collect(); commandParts.push(std::ptr::null()); - execvp(executable as *libc::c_char, commandParts.as_ptr() as **libc::c_char) as int + execvp(executable as *const libc::c_char, commandParts.as_ptr() as *mut *const libc::c_char) as int } } @@ -129,7 +129,7 @@ fn enter_chroot(root: &Path) { crash!(1, "cannot chdir to {}", rootStr) }; let err = unsafe { - chroot(".".to_c_str().unwrap() as *libc::c_char) + chroot(".".to_c_str().unwrap() as *const libc::c_char) }; if err != 0 { crash!(1, "cannot chroot to {}: {:s}", rootStr, strerror(err).as_slice()) @@ -194,7 +194,7 @@ fn set_user(user: &str) { fn strerror(errno: i32) -> String { unsafe { let err = libc::funcs::c95::string::strerror(errno); - std::str::raw::from_c_str(err) + std::str::raw::from_c_str(err as *const i8) } } diff --git a/common/c_types.rs b/common/c_types.rs index b8c16e43f..9a42b8ce5 100644 --- a/common/c_types.rs +++ b/common/c_types.rs @@ -14,32 +14,32 @@ use self::libc::funcs::posix88::unistd::getgroups; use std::vec::Vec; use std::os; -use std::ptr::read; +use std::ptr::{mut_null, read}; use std::str::raw::from_c_str; #[cfg(target_os = "macos")] pub struct c_passwd { - pub pw_name: *c_char, /* user name */ - pub pw_passwd: *c_char, /* user name */ + pub pw_name: *const c_char, /* user name */ + pub pw_passwd: *const c_char, /* user name */ pub pw_uid: uid_t, /* user uid */ pub pw_gid: gid_t, /* user gid */ pub pw_change: time_t, - pub pw_class: *c_char, - pub pw_gecos: *c_char, - pub pw_dir: *c_char, - pub pw_shell: *c_char, + pub pw_class: *const c_char, + pub pw_gecos: *const c_char, + pub pw_dir: *const c_char, + pub pw_shell: *const c_char, pub pw_expire: time_t } #[cfg(target_os = "linux")] pub struct c_passwd { - pub pw_name: *c_char, /* user name */ - pub pw_passwd: *c_char, /* user name */ + pub pw_name: *const c_char, /* user name */ + pub pw_passwd: *const c_char, /* user name */ pub pw_uid: uid_t, /* user uid */ pub pw_gid: gid_t, /* user gid */ - pub pw_gecos: *c_char, - pub pw_dir: *c_char, - pub pw_shell: *c_char, + pub pw_gecos: *const c_char, + pub pw_dir: *const c_char, + pub pw_shell: *const c_char, } #[cfg(target_os = "macos")] @@ -62,10 +62,10 @@ pub struct utsname { } pub struct c_group { - pub gr_name: *c_char, // group name - pub gr_passwd: *c_char, // password + pub gr_name: *const c_char, // group name + pub gr_passwd: *const c_char, // password pub gr_gid: gid_t, // group id - pub gr_mem: **c_char, // member list + pub gr_mem: *const *const c_char, // member list } pub struct c_tm { @@ -81,11 +81,11 @@ pub struct c_tm { } extern { - pub fn getpwuid(uid: uid_t) -> *c_passwd; - pub fn getpwnam(login: *c_char) -> *c_passwd; - pub fn getgrgid(gid: gid_t) -> *c_group; - pub fn getgrnam(name: *c_char) -> *c_group; - pub fn getgrouplist(name: *c_char, + pub fn getpwuid(uid: uid_t) -> *const c_passwd; + pub fn getpwnam(login: *const c_char) -> *const c_passwd; + pub fn getgrgid(gid: gid_t) -> *const c_group; + pub fn getgrnam(name: *const c_char) -> *const c_group; + pub fn getgrouplist(name: *const c_char, gid: gid_t, groups: *mut gid_t, ngroups: *mut c_int) -> c_int; @@ -93,7 +93,7 @@ extern { #[cfg(target_os = "macos")] extern { - pub fn getgroupcount(name: *c_char, gid: gid_t) -> int32_t; + pub fn getgroupcount(name: *const c_char, gid: gid_t) -> int32_t; } pub fn get_pw_from_args(free: &Vec) -> Option { @@ -114,7 +114,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 *libc::c_char) + getpwnam(username.as_slice().to_c_str().unwrap() as *const libc::c_char) }; if pw_pointer.is_not_null() { Some(unsafe { read(pw_pointer) }) @@ -131,7 +131,7 @@ pub fn get_group(groupname: &str) -> Option { let group = if groupname.chars().all(|c| c.is_digit()) { unsafe { getgrgid(from_str::(groupname).unwrap()) } } else { - unsafe { getgrnam(groupname.to_c_str().unwrap() as *c_char) } + unsafe { getgrnam(groupname.to_c_str().unwrap() as *const c_char) } }; if group.is_not_null() { @@ -142,7 +142,7 @@ pub fn get_group(groupname: &str) -> Option { } } -pub fn get_group_list(name: *c_char, gid: gid_t) -> Vec { +pub fn get_group_list(name: *const c_char, gid: gid_t) -> Vec { let mut ngroups: c_int = 32; let mut groups: Vec = Vec::with_capacity(ngroups as uint); @@ -159,12 +159,12 @@ pub fn get_group_list(name: *c_char, gid: gid_t) -> Vec { #[cfg(target_os = "linux")] #[inline(always)] -unsafe fn get_group_list_internal(name: *c_char, gid: gid_t, groups: *mut gid_t, grcnt: *mut c_int) -> c_int { +unsafe fn get_group_list_internal(name: *const c_char, gid: gid_t, groups: *mut gid_t, grcnt: *mut c_int) -> c_int { getgrouplist(name, gid, groups, grcnt) } #[cfg(target_os = "macos")] -unsafe fn get_group_list_internal(name: *c_char, gid: gid_t, groups: *mut gid_t, grcnt: *mut c_int) -> c_int { +unsafe fn get_group_list_internal(name: *const c_char, gid: gid_t, groups: *mut gid_t, grcnt: *mut c_int) -> c_int { let ngroups = getgroupcount(name, gid); let oldsize = *grcnt; *grcnt = ngroups; @@ -177,7 +177,7 @@ unsafe fn get_group_list_internal(name: *c_char, gid: gid_t, groups: *mut gid_t, } pub fn get_groups() -> Result, int> { - let ngroups = unsafe { getgroups(0, 0 as *mut gid_t) }; + let ngroups = unsafe { getgroups(0, mut_null()) }; if ngroups == -1 { return Err(os::errno()); } diff --git a/echo/echo.rs b/echo/echo.rs index ebdfbc470..ea7239b8d 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -97,7 +97,7 @@ fn parse_options(args: Vec, options: &mut EchoOptions) -> Option { if arg.len() > 1 && arg.as_slice().char_at(0) == '-' { let mut newopts = options.clone(); - let argptr: *String = &arg; // escape from the borrow checker + let argptr: *const String = &arg; // escape from the borrow checker for ch in unsafe { (*argptr).as_slice() }.chars().skip(1) { match ch { 'h' => { diff --git a/hostname/hostname.rs b/hostname/hostname.rs index 9d35c306c..632f73e3d 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -19,17 +19,17 @@ use std::str; use getopts::{optflag, getopts, usage}; extern { - fn gethostname(name: *libc::c_char, namelen: libc::size_t) -> libc::c_int; + fn gethostname(name: *mut 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; + fn sethostname(name: *const 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; + fn sethostname(name: *const libc::c_char, namelen: libc::size_t) -> libc::c_int; } pub fn uumain(args: Vec) -> int { @@ -92,7 +92,7 @@ fn xgethostname() -> String { let mut name = Vec::from_elem(namelen, 0u8); let err = unsafe { - gethostname (name.as_mut_ptr() as *libc::c_char, + gethostname (name.as_mut_ptr() as *mut libc::c_char, namelen as libc::size_t) }; diff --git a/id/id.rs b/id/id.rs index 4ddcde852..8e9d33176 100644 --- a/id/id.rs +++ b/id/id.rs @@ -72,12 +72,12 @@ mod audit { pub type c_auditinfo_addr_t = c_auditinfo_addr; extern { - pub fn getaudit(auditinfo_addr: *c_auditinfo_addr_t) -> c_int; + pub fn getaudit(auditinfo_addr: *mut c_auditinfo_addr_t) -> c_int; } } extern { - fn getgrgid(gid: uid_t) -> *c_group; + fn getgrgid(gid: uid_t) -> *const c_group; } static NAME: &'static str = "id"; @@ -198,7 +198,7 @@ fn pretty(possible_pw: Option) { print!("uid\t{:s}\ngroups\t", pw_name); group(possible_pw, true); } else { - let login = unsafe { from_c_str(getlogin()) }; + let login = unsafe { from_c_str(getlogin() as *const i8) }; let rid = unsafe { getuid() }; let pw = unsafe { getpwuid(rid) }; @@ -308,7 +308,7 @@ fn auditid() { } #[cfg(not(target_os = "linux"))] fn auditid() { let auditinfo: audit::c_auditinfo_addr_t = unsafe { audit::uninitialized() }; - let address = &auditinfo as *audit::c_auditinfo_addr_t; + let address = &auditinfo as *mut audit::c_auditinfo_addr_t; if unsafe { audit::getaudit(address) } < 0 { println!("couldn't retrieve information"); return; diff --git a/logname/logname.rs b/logname/logname.rs index eb5e5abc0..4f32aa5ea 100644 --- a/logname/logname.rs +++ b/logname/logname.rs @@ -26,11 +26,11 @@ use libc::c_char; extern { // POSIX requires using getlogin (or equivalent code) - pub fn getlogin() -> *libc::c_char; + pub fn getlogin() -> *const libc::c_char; } unsafe fn get_userlogin() -> String { - let login: *libc::c_char = getlogin(); + let login: *const libc::c_char = getlogin(); str::raw::from_c_str(login) } diff --git a/nohup/nohup.rs b/nohup/nohup.rs index 492503eee..87d48f90f 100644 --- a/nohup/nohup.rs +++ b/nohup/nohup.rs @@ -30,7 +30,7 @@ static VERSION: &'static str = "1.0.0"; #[cfg(target_os = "macos")] extern { - fn _vprocmgr_detach_from_console(flags: u32) -> *libc::c_int; + fn _vprocmgr_detach_from_console(flags: u32) -> *const libc::c_int; } #[cfg(target_os = "macos")] @@ -43,7 +43,7 @@ fn rewind_stdout(s: &mut T) { #[cfg(target_os = "linux")] #[cfg(target_os = "freebsd")] -fn _vprocmgr_detach_from_console(_: u32) -> *libc::c_int { std::ptr::null() } +fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() } #[cfg(target_os = "linux")] #[cfg(target_os = "freebsd")] @@ -83,9 +83,9 @@ pub fn uumain(args: Vec) -> int { unsafe { // we ignore the memory leak here because it doesn't matter anymore let executable = opts.free.get(0).as_slice().to_c_str().unwrap(); - let mut args: Vec<*i8> = opts.free.iter().map(|x| x.to_c_str().unwrap()).collect(); + let mut args: Vec<*const i8> = opts.free.iter().map(|x| x.to_c_str().unwrap()).collect(); args.push(std::ptr::null()); - execvp(executable as *libc::c_char, args.as_ptr() as **libc::c_char) as int + execvp(executable as *const libc::c_char, args.as_ptr() as *mut *const libc::c_char) as int } } diff --git a/realpath/realpath.rs b/realpath/realpath.rs index a8b89401a..a17302fa5 100644 --- a/realpath/realpath.rs +++ b/realpath/realpath.rs @@ -78,7 +78,7 @@ fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool { Some(x) => x, }; - let mut links_left = 256; + let mut links_left = 256i; for part in abs.components() { result.push(part); diff --git a/seq/seq.rs b/seq/seq.rs index 188b44fd2..994db7b82 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -85,7 +85,7 @@ fn parse_options(args: Vec, options: &mut SeqOptions) -> Result { if arg.len() > 1 && arg.as_slice().char_at(0) == '-' { - let argptr: *String = &arg; // escape from the borrow checker + let argptr: *const String = &arg; // escape from the borrow checker let mut chiter = unsafe { (*argptr).as_slice() }.chars().skip(1); let mut ch = ' '; while match chiter.next() { Some(m) => { ch = m; true } None => false } { diff --git a/sync/sync.rs b/sync/sync.rs index 7533bebe3..15b1ad809 100644 --- a/sync/sync.rs +++ b/sync/sync.rs @@ -16,6 +16,7 @@ extern crate getopts; extern crate libc; use getopts::{optflag, getopts, usage}; +#[cfg(windows)]use std::ptr::null; #[path = "../common/util.rs"] mod util; @@ -39,22 +40,22 @@ mod platform { use std::{mem, str}; extern "system" { - fn CreateFileA(lpFileName: *libc::c_char, + fn CreateFileA(lpFileName: *const libc::c_char, dwDesiredAccess: libc::uint32_t, dwShareMode: libc::uint32_t, - lpSecurityAttributes: *libc::c_void, // *LPSECURITY_ATTRIBUTES + lpSecurityAttributes: *const libc::c_void, // *LPSECURITY_ATTRIBUTES dwCreationDisposition: libc::uint32_t, dwFlagsAndAttributes: libc::uint32_t, - hTemplateFile: *libc::c_void) -> *libc::c_void; - fn GetDriveTypeA(lpRootPathName: *libc::c_char) -> libc::c_uint; + hTemplateFile: *const libc::c_void) -> *const libc::c_void; + fn GetDriveTypeA(lpRootPathName: *const libc::c_char) -> libc::c_uint; fn GetLastError() -> libc::uint32_t; - fn FindFirstVolumeA(lpszVolumeName: *libc::c_char, - cchBufferLength: libc::uint32_t) -> *libc::c_void; - fn FindNextVolumeA(hFindVolume: *libc::c_void, - lpszVolumeName: *libc::c_char, + fn FindFirstVolumeA(lpszVolumeName: *mut libc::c_char, + cchBufferLength: libc::uint32_t) -> *const libc::c_void; + fn FindNextVolumeA(hFindVolume: *const libc::c_void, + lpszVolumeName: *mut libc::c_char, cchBufferLength: libc::uint32_t) -> libc::c_int; - fn FindVolumeClose(hFindVolume: *libc::c_void) -> libc::c_int; - fn FlushFileBuffers(hFile: *libc::c_void) -> libc::c_int; + fn FindVolumeClose(hFindVolume: *const libc::c_void) -> libc::c_int; + fn FlushFileBuffers(hFile: *const libc::c_void) -> libc::c_int; } #[allow(unused_unsafe)] @@ -66,11 +67,11 @@ mod platform { match CreateFileA(sliced_name_buffer, 0xC0000000, // GENERIC_WRITE 0x00000003, // FILE_SHARE_WRITE, - 0 as *libc::c_void, + null(), 0x00000003, // OPEN_EXISTING 0, - 0 as *libc::c_void) { - _x if _x == -1 as *libc::c_void => { // INVALID_HANDLE_VALUE + null()) { + _x if _x == -1 as *const libc::c_void => { // INVALID_HANDLE_VALUE crash!(GetLastError(), "failed to create volume handle"); } handle @ _ => { @@ -85,10 +86,10 @@ mod platform { } #[allow(unused_unsafe)] - unsafe fn find_first_volume() -> (String, *libc::c_void) { + unsafe fn find_first_volume() -> (String, *const libc::c_void) { let name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH match FindFirstVolumeA(name.as_ptr(), name.len() as libc::uint32_t) { - _x if _x == -1 as *libc::c_void => { // INVALID_HANDLE_VALUE + _x if _x == -1 as *const libc::c_void => { // INVALID_HANDLE_VALUE crash!(GetLastError(), "failed to find first volume"); } handle @ _ => { diff --git a/tty/tty.rs b/tty/tty.rs index a74662913..c664e471b 100644 --- a/tty/tty.rs +++ b/tty/tty.rs @@ -28,7 +28,7 @@ use getopts::{optflag,getopts}; mod util; extern { - fn ttyname(filedesc: libc::c_int) -> *libc::c_char; + fn ttyname(filedesc: libc::c_int) -> *const libc::c_char; fn isatty(filedesc: libc::c_int) -> libc::c_int; } diff --git a/uptime/uptime.rs b/uptime/uptime.rs index 796eee351..e21f068a2 100644 --- a/uptime/uptime.rs +++ b/uptime/uptime.rs @@ -19,7 +19,7 @@ extern crate libc; use std::mem::transmute; use std::io::{print, File}; -use std::ptr::null; +use std::ptr::{mut_null, null}; use std::from_str::from_str; use libc::{time_t, c_double, c_int, c_char}; use c_types::c_tm; @@ -34,16 +34,16 @@ use utmpx::*; static NAME: &'static str = "uptime"; extern { - fn time(timep: *time_t) -> time_t; - fn localtime(timep: *time_t) -> *c_tm; + fn time(timep: *mut time_t) -> time_t; + fn localtime(timep: *const time_t) -> *const c_tm; - fn getloadavg(loadavg: *c_double, nelem: c_int) -> c_int; + fn getloadavg(loadavg: *mut c_double, nelem: c_int) -> c_int; - fn getutxent() -> *c_utmp; + fn getutxent() -> *const c_utmp; fn setutxent(); fn endutxent(); - fn utmpxname(file: *c_char) -> c_int; + fn utmpxname(file: *const c_char) -> c_int; } pub fn uumain(args: Vec) -> int { @@ -81,8 +81,8 @@ pub fn uumain(args: Vec) -> int { } fn print_loadavg() { - let avg: [c_double, ..3] = [0.0, ..3]; - let loads: i32 = unsafe { transmute(getloadavg(avg.as_ptr(), 3)) }; + let mut avg: [c_double, ..3] = [0.0, ..3]; + let loads: i32 = unsafe { transmute(getloadavg(avg.as_mut_ptr(), 3)) }; if loads == -1 { print!("\n"); @@ -143,7 +143,7 @@ fn print_nusers(nusers: uint) { } fn print_time() { - let local_time = unsafe { *localtime(&time(null())) }; + let local_time = unsafe { *localtime(&time(mut_null())) }; if local_time.tm_hour >= 0 && local_time.tm_min >= 0 && local_time.tm_sec >= 0 { @@ -160,7 +160,7 @@ fn get_uptime(boot_time: Option) -> i64 { Ok(s) => s, _ => return match boot_time { Some(t) => { - let now = unsafe { time(null()) }; + let now = unsafe { time(mut_null()) }; ((now - t) * 100) as i64 // Return in ms }, _ => -1 diff --git a/users/users.rs b/users/users.rs index e359c3eb3..69a4f2194 100644 --- a/users/users.rs +++ b/users/users.rs @@ -32,16 +32,16 @@ mod util; mod utmpx; extern { - fn getutxent() -> *c_utmp; - fn getutxid(ut: *c_utmp) -> *c_utmp; - fn getutxline(ut: *c_utmp) -> *c_utmp; + fn getutxent() -> *const c_utmp; + fn getutxid(ut: *const c_utmp) -> *const c_utmp; + fn getutxline(ut: *const c_utmp) -> *const c_utmp; - fn pututxline(ut: *c_utmp) -> *c_utmp; + fn pututxline(ut: *const c_utmp) -> *const c_utmp; fn setutxent(); fn endutxent(); - fn utmpxname(file: *libc::c_char) -> libc::c_int; + fn utmpxname(file: *const libc::c_char) -> libc::c_int; } static NAME: &'static str = "users"; diff --git a/whoami/whoami.rs b/whoami/whoami.rs index ad3080263..ea56b9da8 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -35,9 +35,9 @@ mod platform { } pub unsafe fn getusername() -> String { - let passwd: *c_passwd = getpwuid(geteuid()); + let passwd: *const c_passwd = getpwuid(geteuid()); - let pw_name: *libc::c_char = (*passwd).pw_name; + let pw_name: *const libc::c_char = (*passwd).pw_name; let name = str::raw::from_c_str(pw_name); name @@ -51,7 +51,7 @@ mod platform { use std::str; extern "system" { - pub fn GetUserNameA(out: *libc::c_char, len: *libc::uint32_t) -> libc::uint8_t; + pub fn GetUserNameA(out: *mut libc::c_char, len: *mut libc::uint32_t) -> libc::uint8_t; } #[allow(unused_unsafe)]