Merge branch 'ctermid' into 'master'

Implement ctermid()

See merge request redox-os/relibc!490
This commit is contained in:
Jeremy Soller
2024-08-01 18:42:29 +00:00
4 changed files with 34 additions and 3 deletions
+2
View File
@@ -24,6 +24,8 @@ pub const _IOFBF: c_int = 0;
pub const _IOLBF: c_int = 1;
pub const _IONBF: c_int = 2;
// /dev/tty + nul
pub const L_ctermid: usize = 9;
// form of name is /XXXXXX, so 7
pub const L_tmpnam: c_int = 7;
// 36^6 (26 letters + 10 digits) is larger than i32::MAX, so just set to that
+9 -3
View File
@@ -278,9 +278,15 @@ pub unsafe extern "C" fn clearerr(stream: *mut FILE) {
stream.flags &= !(F_EOF | F_ERR);
}
// #[no_mangle]
pub extern "C" fn ctermid(_s: *mut c_char) -> *mut c_char {
unimplemented!();
#[no_mangle]
pub unsafe extern "C" fn ctermid(s: *mut c_char) -> *mut c_char {
static mut TERMID: [u8; L_ctermid] = *b"/dev/tty\0";
if s.is_null() {
return TERMID.as_mut_ptr() as *mut c_char;
}
strncpy(s, TERMID.as_mut_ptr() as *mut c_char, L_ctermid)
}
// #[no_mangle]