Merge branch 'cuserid_impl' into 'master'
stdio: implements legacy cuserid proposal. See merge request redox-os/relibc!362
This commit is contained in:
@@ -27,13 +27,13 @@ use self::redox as sys;
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct passwd {
|
||||
pw_name: *mut c_char,
|
||||
pw_passwd: *mut c_char,
|
||||
pw_uid: uid_t,
|
||||
pw_gid: gid_t,
|
||||
pw_gecos: *mut c_char,
|
||||
pw_dir: *mut c_char,
|
||||
pw_shell: *mut c_char,
|
||||
pub pw_name: *mut c_char,
|
||||
pub pw_passwd: *mut c_char,
|
||||
pub pw_uid: uid_t,
|
||||
pub pw_gid: gid_t,
|
||||
pub pw_gecos: *mut c_char,
|
||||
pub pw_dir: *mut c_char,
|
||||
pub pw_shell: *mut c_char,
|
||||
}
|
||||
|
||||
static mut PASSWD_BUF: Option<MaybeAllocated> = None;
|
||||
|
||||
+20
-4
@@ -20,8 +20,8 @@ use crate::{
|
||||
fs::File,
|
||||
header::{
|
||||
errno::{self, STR_ERROR},
|
||||
fcntl, stdlib,
|
||||
string::{self, strlen},
|
||||
fcntl, stdlib, pwd,
|
||||
string::{self, strlen, strncpy},
|
||||
unistd,
|
||||
},
|
||||
io::{self, BufRead, BufWriter, LineWriter, Read, Write},
|
||||
@@ -272,8 +272,24 @@ pub extern "C" fn ctermid(_s: *mut c_char) -> *mut c_char {
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn cuserid(_s: *mut c_char) -> *mut c_char {
|
||||
unimplemented!();
|
||||
pub unsafe extern "C" fn cuserid(s: *mut c_char) -> *mut c_char {
|
||||
let mut buf: Vec<i8> = vec![0; 256];
|
||||
let mut pwd: pwd::passwd = unsafe { mem::zeroed() };
|
||||
let mut pwdbuf: *mut pwd::passwd = unsafe { mem::zeroed() };
|
||||
if s != ptr::null_mut() {
|
||||
*s.add(0) = 0;
|
||||
}
|
||||
pwd::getpwuid_r(unistd::geteuid(), &mut pwd, buf.as_mut_ptr(), buf.len(), &mut pwdbuf);
|
||||
if pwdbuf == ptr::null_mut() {
|
||||
return s;
|
||||
}
|
||||
|
||||
if s != ptr::null_mut() {
|
||||
strncpy(s, (*pwdbuf).pw_name, unistd::L_cuserid);
|
||||
return s;
|
||||
}
|
||||
|
||||
(*pwdbuf).pw_name
|
||||
}
|
||||
|
||||
/// Close a file
|
||||
|
||||
@@ -479,7 +479,7 @@ pub unsafe extern "C" fn strlcpy(dst: *mut c_char, src: *const c_char, n: size_t
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strlcat(dst: *mut c_char, src: *const c_char, n: size_t) -> size_t {
|
||||
let len = strlen(dst) as isize;
|
||||
let mut d = dst.offset(len);
|
||||
let d = dst.offset(len);
|
||||
|
||||
strlcpy(d, src, n)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ pub const STDIN_FILENO: c_int = 0;
|
||||
pub const STDOUT_FILENO: c_int = 1;
|
||||
pub const STDERR_FILENO: c_int = 2;
|
||||
|
||||
pub const L_cuserid: usize = 9;
|
||||
|
||||
#[thread_local]
|
||||
pub static mut fork_hooks_static: Option<[LinkedList<extern "C" fn()>; 3]> = None;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user