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]
+1
View File
@@ -161,6 +161,7 @@ NAMES=\
pwd \
sa_restart \
sigchld \
stdio/ctermid \
stdio/tempnam \
stdio/tmpnam \
stdlib/bsearch \
+22
View File
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
#define DEVTTY "/dev/tty"
int main(void)
{
char *name = ctermid(NULL);
if(strcmp(name, DEVTTY) != 0) {
printf("ctermid name differs: expected %s, got: %s\n", DEVTTY, name);
return 1;
}
char name2[L_ctermid];
ctermid(name2);
if(strcmp(name, DEVTTY) != 0) {
printf("ctermid name2 differs: expected %s, got: %s\n", DEVTTY, name2);
return 1;
}
return 0;
}