From 19347ed454621161caf4186f1a52ec656c3dc58f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 26 Apr 2021 14:31:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[libc][unistd]=20=E5=AE=8C=E5=96=84isatty()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/unistd.c | 26 +++++++++++++++++---- components/libc/compilers/newlib/syscalls.c | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 20130cbb8a..6c81fc7662 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -15,18 +15,29 @@ #ifdef RT_USING_POSIX_TERMIOS #include "termios.h" - int isatty(int fd) { struct termios ts; - return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ + return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/ +} +#else +int isatty(int fd) +{ + if (fd >=0 && fd < 3) + { + return 1; + } + else + { + return 0; + } } -RTM_EXPORT(isatty); #endif +RTM_EXPORT(isatty); char *ttyname(int fd) { - return "/dev/tty0"; /*TODO: need to add more specific*/ + return "/dev/tty"; /*TODO: need to add more specific*/ } RTM_EXPORT(ttyname); @@ -50,11 +61,16 @@ int usleep(useconds_t usec) } RTM_EXPORT(usleep); -pid_t getpid(void) +pid_t gettid(void) { /*TODO*/ return 0; } + +pid_t getpid(void) +{ + return gettid(); +} RTM_EXPORT(getpid); pid_t getppid(void) diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 6cbc11fd6a..7c5d51eca6 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -98,6 +98,7 @@ _isatty_r(struct _reent *ptr, int fd) return 0; } } + int _kill_r(struct _reent *ptr, int pid, int sig) { From cb7fa8fceaf5b9e2aacaee132ce5bb0ad49c92aa Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 26 Apr 2021 14:34:26 +0800 Subject: [PATCH 2/2] implement pid_t gettid(void) --- components/libc/compilers/common/none-gcc/sys/unistd.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index 7752a1caf7..2f01f660b3 100644 --- a/components/libc/compilers/common/none-gcc/sys/unistd.h +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -66,13 +66,11 @@ #endif - int isatty (int fd); char * ttyname (int desc); - unsigned int sleep(unsigned int seconds); int usleep(useconds_t usec); - +pid_t gettid(void); pid_t getpid(void); pid_t getppid(void); uid_t getuid(void);