Merge branch 'ctermid' into 'master'
Implement ctermid() See merge request redox-os/relibc!490
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -161,6 +161,7 @@ NAMES=\
|
||||
pwd \
|
||||
sa_restart \
|
||||
sigchld \
|
||||
stdio/ctermid \
|
||||
stdio/tempnam \
|
||||
stdio/tmpnam \
|
||||
stdlib/bsearch \
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user