mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
Remove use of raw bare pointers (*T -> *const T)
This commit is contained in:
parent
e5066d1978
commit
22743f04ae
14 changed files with 86 additions and 85 deletions
|
@ -20,17 +20,17 @@ use libc::funcs::posix88::unistd::{execvp, setuid, setgid};
|
||||||
#[path = "../common/c_types.rs"] mod c_types;
|
#[path = "../common/c_types.rs"] mod c_types;
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
fn chroot(path: *libc::c_char) -> libc::c_int;
|
fn chroot(path: *const libc::c_char) -> libc::c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
extern {
|
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")]
|
#[cfg(target_os = "linux")]
|
||||||
extern {
|
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";
|
static NAME: &'static str = "chroot";
|
||||||
|
@ -92,9 +92,9 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let executable = command.get(0).as_slice().to_c_str().unwrap();
|
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());
|
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)
|
crash!(1, "cannot chdir to {}", rootStr)
|
||||||
};
|
};
|
||||||
let err = unsafe {
|
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 {
|
if err != 0 {
|
||||||
crash!(1, "cannot chroot to {}: {:s}", rootStr, strerror(err).as_slice())
|
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 {
|
fn strerror(errno: i32) -> String {
|
||||||
unsafe {
|
unsafe {
|
||||||
let err = libc::funcs::c95::string::strerror(errno);
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,32 +14,32 @@ use self::libc::funcs::posix88::unistd::getgroups;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::ptr::read;
|
use std::ptr::{mut_null, read};
|
||||||
use std::str::raw::from_c_str;
|
use std::str::raw::from_c_str;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub struct c_passwd {
|
pub struct c_passwd {
|
||||||
pub pw_name: *c_char, /* user name */
|
pub pw_name: *const c_char, /* user name */
|
||||||
pub pw_passwd: *c_char, /* user name */
|
pub pw_passwd: *const c_char, /* user name */
|
||||||
pub pw_uid: uid_t, /* user uid */
|
pub pw_uid: uid_t, /* user uid */
|
||||||
pub pw_gid: gid_t, /* user gid */
|
pub pw_gid: gid_t, /* user gid */
|
||||||
pub pw_change: time_t,
|
pub pw_change: time_t,
|
||||||
pub pw_class: *c_char,
|
pub pw_class: *const c_char,
|
||||||
pub pw_gecos: *c_char,
|
pub pw_gecos: *const c_char,
|
||||||
pub pw_dir: *c_char,
|
pub pw_dir: *const c_char,
|
||||||
pub pw_shell: *c_char,
|
pub pw_shell: *const c_char,
|
||||||
pub pw_expire: time_t
|
pub pw_expire: time_t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub struct c_passwd {
|
pub struct c_passwd {
|
||||||
pub pw_name: *c_char, /* user name */
|
pub pw_name: *const c_char, /* user name */
|
||||||
pub pw_passwd: *c_char, /* user name */
|
pub pw_passwd: *const c_char, /* user name */
|
||||||
pub pw_uid: uid_t, /* user uid */
|
pub pw_uid: uid_t, /* user uid */
|
||||||
pub pw_gid: gid_t, /* user gid */
|
pub pw_gid: gid_t, /* user gid */
|
||||||
pub pw_gecos: *c_char,
|
pub pw_gecos: *const c_char,
|
||||||
pub pw_dir: *c_char,
|
pub pw_dir: *const c_char,
|
||||||
pub pw_shell: *c_char,
|
pub pw_shell: *const c_char,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -62,10 +62,10 @@ pub struct utsname {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct c_group {
|
pub struct c_group {
|
||||||
pub gr_name: *c_char, // group name
|
pub gr_name: *const c_char, // group name
|
||||||
pub gr_passwd: *c_char, // password
|
pub gr_passwd: *const c_char, // password
|
||||||
pub gr_gid: gid_t, // group id
|
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 {
|
pub struct c_tm {
|
||||||
|
@ -81,11 +81,11 @@ pub struct c_tm {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
pub fn getpwuid(uid: uid_t) -> *c_passwd;
|
pub fn getpwuid(uid: uid_t) -> *const c_passwd;
|
||||||
pub fn getpwnam(login: *c_char) -> *c_passwd;
|
pub fn getpwnam(login: *const c_char) -> *const c_passwd;
|
||||||
pub fn getgrgid(gid: gid_t) -> *c_group;
|
pub fn getgrgid(gid: gid_t) -> *const c_group;
|
||||||
pub fn getgrnam(name: *c_char) -> *c_group;
|
pub fn getgrnam(name: *const c_char) -> *const c_group;
|
||||||
pub fn getgrouplist(name: *c_char,
|
pub fn getgrouplist(name: *const c_char,
|
||||||
gid: gid_t,
|
gid: gid_t,
|
||||||
groups: *mut gid_t,
|
groups: *mut gid_t,
|
||||||
ngroups: *mut c_int) -> c_int;
|
ngroups: *mut c_int) -> c_int;
|
||||||
|
@ -93,7 +93,7 @@ extern {
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
extern {
|
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<String>) -> Option<c_passwd> {
|
pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
||||||
|
@ -114,7 +114,7 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
||||||
// Passed the username as a string
|
// Passed the username as a string
|
||||||
} else {
|
} else {
|
||||||
let pw_pointer = unsafe {
|
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() {
|
if pw_pointer.is_not_null() {
|
||||||
Some(unsafe { read(pw_pointer) })
|
Some(unsafe { read(pw_pointer) })
|
||||||
|
@ -131,7 +131,7 @@ pub fn get_group(groupname: &str) -> Option<c_group> {
|
||||||
let group = if groupname.chars().all(|c| c.is_digit()) {
|
let group = if groupname.chars().all(|c| c.is_digit()) {
|
||||||
unsafe { getgrgid(from_str::<gid_t>(groupname).unwrap()) }
|
unsafe { getgrgid(from_str::<gid_t>(groupname).unwrap()) }
|
||||||
} else {
|
} 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() {
|
if group.is_not_null() {
|
||||||
|
@ -142,7 +142,7 @@ pub fn get_group(groupname: &str) -> Option<c_group> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_group_list(name: *c_char, gid: gid_t) -> Vec<gid_t> {
|
pub fn get_group_list(name: *const c_char, gid: gid_t) -> Vec<gid_t> {
|
||||||
let mut ngroups: c_int = 32;
|
let mut ngroups: c_int = 32;
|
||||||
let mut groups: Vec<gid_t> = Vec::with_capacity(ngroups as uint);
|
let mut groups: Vec<gid_t> = Vec::with_capacity(ngroups as uint);
|
||||||
|
|
||||||
|
@ -159,12 +159,12 @@ pub fn get_group_list(name: *c_char, gid: gid_t) -> Vec<gid_t> {
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[inline(always)]
|
#[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)
|
getgrouplist(name, gid, groups, grcnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[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 ngroups = getgroupcount(name, gid);
|
||||||
let oldsize = *grcnt;
|
let oldsize = *grcnt;
|
||||||
*grcnt = ngroups;
|
*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<Vec<gid_t>, int> {
|
pub fn get_groups() -> Result<Vec<gid_t>, int> {
|
||||||
let ngroups = unsafe { getgroups(0, 0 as *mut gid_t) };
|
let ngroups = unsafe { getgroups(0, mut_null()) };
|
||||||
if ngroups == -1 {
|
if ngroups == -1 {
|
||||||
return Err(os::errno());
|
return Err(os::errno());
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<Str
|
||||||
_ => {
|
_ => {
|
||||||
if arg.len() > 1 && arg.as_slice().char_at(0) == '-' {
|
if arg.len() > 1 && arg.as_slice().char_at(0) == '-' {
|
||||||
let mut newopts = options.clone();
|
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) {
|
for ch in unsafe { (*argptr).as_slice() }.chars().skip(1) {
|
||||||
match ch {
|
match ch {
|
||||||
'h' => {
|
'h' => {
|
||||||
|
|
|
@ -19,17 +19,17 @@ use std::str;
|
||||||
use getopts::{optflag, getopts, usage};
|
use getopts::{optflag, getopts, usage};
|
||||||
|
|
||||||
extern {
|
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")]
|
#[cfg(target_os = "macos")]
|
||||||
extern {
|
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")]
|
#[cfg(target_os = "linux")]
|
||||||
extern {
|
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<String>) -> int {
|
pub fn uumain(args: Vec<String>) -> int {
|
||||||
|
@ -92,7 +92,7 @@ fn xgethostname() -> String {
|
||||||
let mut name = Vec::from_elem(namelen, 0u8);
|
let mut name = Vec::from_elem(namelen, 0u8);
|
||||||
|
|
||||||
let err = unsafe {
|
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)
|
namelen as libc::size_t)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
8
id/id.rs
8
id/id.rs
|
@ -72,12 +72,12 @@ mod audit {
|
||||||
pub type c_auditinfo_addr_t = c_auditinfo_addr;
|
pub type c_auditinfo_addr_t = c_auditinfo_addr;
|
||||||
|
|
||||||
extern {
|
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 {
|
extern {
|
||||||
fn getgrgid(gid: uid_t) -> *c_group;
|
fn getgrgid(gid: uid_t) -> *const c_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NAME: &'static str = "id";
|
static NAME: &'static str = "id";
|
||||||
|
@ -198,7 +198,7 @@ fn pretty(possible_pw: Option<c_passwd>) {
|
||||||
print!("uid\t{:s}\ngroups\t", pw_name);
|
print!("uid\t{:s}\ngroups\t", pw_name);
|
||||||
group(possible_pw, true);
|
group(possible_pw, true);
|
||||||
} else {
|
} else {
|
||||||
let login = unsafe { from_c_str(getlogin()) };
|
let login = unsafe { from_c_str(getlogin() as *const i8) };
|
||||||
let rid = unsafe { getuid() };
|
let rid = unsafe { getuid() };
|
||||||
let pw = unsafe { getpwuid(rid) };
|
let pw = unsafe { getpwuid(rid) };
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ fn auditid() { }
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
fn auditid() {
|
fn auditid() {
|
||||||
let auditinfo: audit::c_auditinfo_addr_t = unsafe { audit::uninitialized() };
|
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 {
|
if unsafe { audit::getaudit(address) } < 0 {
|
||||||
println!("couldn't retrieve information");
|
println!("couldn't retrieve information");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -26,11 +26,11 @@ use libc::c_char;
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
// POSIX requires using getlogin (or equivalent code)
|
// 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 {
|
unsafe fn get_userlogin() -> String {
|
||||||
let login: *libc::c_char = getlogin();
|
let login: *const libc::c_char = getlogin();
|
||||||
|
|
||||||
str::raw::from_c_str(login)
|
str::raw::from_c_str(login)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
extern {
|
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")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -43,7 +43,7 @@ fn rewind_stdout<T: std::rt::rtio::RtioFileStream>(s: &mut T) {
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[cfg(target_os = "freebsd")]
|
#[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 = "linux")]
|
||||||
#[cfg(target_os = "freebsd")]
|
#[cfg(target_os = "freebsd")]
|
||||||
|
@ -83,9 +83,9 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
unsafe {
|
unsafe {
|
||||||
// we ignore the memory leak here because it doesn't matter anymore
|
// 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 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());
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut links_left = 256;
|
let mut links_left = 256i;
|
||||||
|
|
||||||
for part in abs.components() {
|
for part in abs.components() {
|
||||||
result.push(part);
|
result.push(part);
|
||||||
|
|
|
@ -85,7 +85,7 @@ fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<Stri
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
if arg.len() > 1 && arg.as_slice().char_at(0) == '-' {
|
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 chiter = unsafe { (*argptr).as_slice() }.chars().skip(1);
|
||||||
let mut ch = ' ';
|
let mut ch = ' ';
|
||||||
while match chiter.next() { Some(m) => { ch = m; true } None => false } {
|
while match chiter.next() { Some(m) => { ch = m; true } None => false } {
|
||||||
|
|
31
sync/sync.rs
31
sync/sync.rs
|
@ -16,6 +16,7 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use getopts::{optflag, getopts, usage};
|
use getopts::{optflag, getopts, usage};
|
||||||
|
#[cfg(windows)]use std::ptr::null;
|
||||||
|
|
||||||
#[path = "../common/util.rs"] mod util;
|
#[path = "../common/util.rs"] mod util;
|
||||||
|
|
||||||
|
@ -39,22 +40,22 @@ mod platform {
|
||||||
use std::{mem, str};
|
use std::{mem, str};
|
||||||
|
|
||||||
extern "system" {
|
extern "system" {
|
||||||
fn CreateFileA(lpFileName: *libc::c_char,
|
fn CreateFileA(lpFileName: *const libc::c_char,
|
||||||
dwDesiredAccess: libc::uint32_t,
|
dwDesiredAccess: libc::uint32_t,
|
||||||
dwShareMode: libc::uint32_t,
|
dwShareMode: libc::uint32_t,
|
||||||
lpSecurityAttributes: *libc::c_void, // *LPSECURITY_ATTRIBUTES
|
lpSecurityAttributes: *const libc::c_void, // *LPSECURITY_ATTRIBUTES
|
||||||
dwCreationDisposition: libc::uint32_t,
|
dwCreationDisposition: libc::uint32_t,
|
||||||
dwFlagsAndAttributes: libc::uint32_t,
|
dwFlagsAndAttributes: libc::uint32_t,
|
||||||
hTemplateFile: *libc::c_void) -> *libc::c_void;
|
hTemplateFile: *const libc::c_void) -> *const libc::c_void;
|
||||||
fn GetDriveTypeA(lpRootPathName: *libc::c_char) -> libc::c_uint;
|
fn GetDriveTypeA(lpRootPathName: *const libc::c_char) -> libc::c_uint;
|
||||||
fn GetLastError() -> libc::uint32_t;
|
fn GetLastError() -> libc::uint32_t;
|
||||||
fn FindFirstVolumeA(lpszVolumeName: *libc::c_char,
|
fn FindFirstVolumeA(lpszVolumeName: *mut libc::c_char,
|
||||||
cchBufferLength: libc::uint32_t) -> *libc::c_void;
|
cchBufferLength: libc::uint32_t) -> *const libc::c_void;
|
||||||
fn FindNextVolumeA(hFindVolume: *libc::c_void,
|
fn FindNextVolumeA(hFindVolume: *const libc::c_void,
|
||||||
lpszVolumeName: *libc::c_char,
|
lpszVolumeName: *mut libc::c_char,
|
||||||
cchBufferLength: libc::uint32_t) -> libc::c_int;
|
cchBufferLength: libc::uint32_t) -> libc::c_int;
|
||||||
fn FindVolumeClose(hFindVolume: *libc::c_void) -> libc::c_int;
|
fn FindVolumeClose(hFindVolume: *const libc::c_void) -> libc::c_int;
|
||||||
fn FlushFileBuffers(hFile: *libc::c_void) -> libc::c_int;
|
fn FlushFileBuffers(hFile: *const libc::c_void) -> libc::c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
|
@ -66,11 +67,11 @@ mod platform {
|
||||||
match CreateFileA(sliced_name_buffer,
|
match CreateFileA(sliced_name_buffer,
|
||||||
0xC0000000, // GENERIC_WRITE
|
0xC0000000, // GENERIC_WRITE
|
||||||
0x00000003, // FILE_SHARE_WRITE,
|
0x00000003, // FILE_SHARE_WRITE,
|
||||||
0 as *libc::c_void,
|
null(),
|
||||||
0x00000003, // OPEN_EXISTING
|
0x00000003, // OPEN_EXISTING
|
||||||
0,
|
0,
|
||||||
0 as *libc::c_void) {
|
null()) {
|
||||||
_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 create volume handle");
|
crash!(GetLastError(), "failed to create volume handle");
|
||||||
}
|
}
|
||||||
handle @ _ => {
|
handle @ _ => {
|
||||||
|
@ -85,10 +86,10 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
#[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
|
let name: [libc::c_char, ..260] = mem::uninitialized(); // MAX_PATH
|
||||||
match FindFirstVolumeA(name.as_ptr(), name.len() as libc::uint32_t) {
|
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");
|
crash!(GetLastError(), "failed to find first volume");
|
||||||
}
|
}
|
||||||
handle @ _ => {
|
handle @ _ => {
|
||||||
|
|
|
@ -28,7 +28,7 @@ use getopts::{optflag,getopts};
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
extern {
|
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;
|
fn isatty(filedesc: libc::c_int) -> libc::c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ extern crate libc;
|
||||||
|
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
use std::io::{print, File};
|
use std::io::{print, File};
|
||||||
use std::ptr::null;
|
use std::ptr::{mut_null, null};
|
||||||
use std::from_str::from_str;
|
use std::from_str::from_str;
|
||||||
use libc::{time_t, c_double, c_int, c_char};
|
use libc::{time_t, c_double, c_int, c_char};
|
||||||
use c_types::c_tm;
|
use c_types::c_tm;
|
||||||
|
@ -34,16 +34,16 @@ use utmpx::*;
|
||||||
static NAME: &'static str = "uptime";
|
static NAME: &'static str = "uptime";
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
fn time(timep: *time_t) -> time_t;
|
fn time(timep: *mut time_t) -> time_t;
|
||||||
fn localtime(timep: *time_t) -> *c_tm;
|
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 setutxent();
|
||||||
fn endutxent();
|
fn endutxent();
|
||||||
|
|
||||||
fn utmpxname(file: *c_char) -> c_int;
|
fn utmpxname(file: *const c_char) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> int {
|
pub fn uumain(args: Vec<String>) -> int {
|
||||||
|
@ -81,8 +81,8 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_loadavg() {
|
fn print_loadavg() {
|
||||||
let avg: [c_double, ..3] = [0.0, ..3];
|
let mut avg: [c_double, ..3] = [0.0, ..3];
|
||||||
let loads: i32 = unsafe { transmute(getloadavg(avg.as_ptr(), 3)) };
|
let loads: i32 = unsafe { transmute(getloadavg(avg.as_mut_ptr(), 3)) };
|
||||||
|
|
||||||
if loads == -1 {
|
if loads == -1 {
|
||||||
print!("\n");
|
print!("\n");
|
||||||
|
@ -143,7 +143,7 @@ fn print_nusers(nusers: uint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_time() {
|
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 &&
|
if local_time.tm_hour >= 0 && local_time.tm_min >= 0 &&
|
||||||
local_time.tm_sec >= 0 {
|
local_time.tm_sec >= 0 {
|
||||||
|
@ -160,7 +160,7 @@ fn get_uptime(boot_time: Option<time_t>) -> i64 {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
_ => return match boot_time {
|
_ => return match boot_time {
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
let now = unsafe { time(null()) };
|
let now = unsafe { time(mut_null()) };
|
||||||
((now - t) * 100) as i64 // Return in ms
|
((now - t) * 100) as i64 // Return in ms
|
||||||
},
|
},
|
||||||
_ => -1
|
_ => -1
|
||||||
|
|
|
@ -32,16 +32,16 @@ mod util;
|
||||||
mod utmpx;
|
mod utmpx;
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
fn getutxent() -> *c_utmp;
|
fn getutxent() -> *const c_utmp;
|
||||||
fn getutxid(ut: *c_utmp) -> *c_utmp;
|
fn getutxid(ut: *const c_utmp) -> *const c_utmp;
|
||||||
fn getutxline(ut: *c_utmp) -> *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 setutxent();
|
||||||
fn endutxent();
|
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";
|
static NAME: &'static str = "users";
|
||||||
|
|
|
@ -35,9 +35,9 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn getusername() -> String {
|
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);
|
let name = str::raw::from_c_str(pw_name);
|
||||||
|
|
||||||
name
|
name
|
||||||
|
@ -51,7 +51,7 @@ mod platform {
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
extern "system" {
|
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)]
|
#[allow(unused_unsafe)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue