From 4dc0fd685bf9892cdeb93bebc8d734a68dd95311 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 19 Jan 1998 22:22:25 +0000 Subject: Patch from Eric Norum: With this in place, it is possible to fdopen a TCP stream socket and getc/fprintf/etc. on the STDIO stream! --- c/src/exec/libcsupport/src/termios.c | 1 + c/src/lib/libc/Makefile.in | 2 +- c/src/lib/libc/syscalls.c | 29 +++++++++++++++++++++++------ c/src/lib/libc/termios.c | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) (limited to 'c/src') diff --git a/c/src/exec/libcsupport/src/termios.c b/c/src/exec/libcsupport/src/termios.c index 8512fd6e14..85e171bd16 100644 --- a/c/src/exec/libcsupport/src/termios.c +++ b/c/src/exec/libcsupport/src/termios.c @@ -113,6 +113,7 @@ struct rtems_termios_tty { int (*read)(int minor); int (*write)(int minor, const char *buf, int len); }; + static struct rtems_termios_tty *ttyHead, *ttyTail; static rtems_id ttyMutex; diff --git a/c/src/lib/libc/Makefile.in b/c/src/lib/libc/Makefile.in index 4e8d3a0320..cce8bd40ca 100644 --- a/c/src/lib/libc/Makefile.in +++ b/c/src/lib/libc/Makefile.in @@ -30,7 +30,7 @@ SRCS=$(C_FILES) $(H_FILES) $(SYS_H_FILES) $(RTEMS_H_FILES) $(PRIVATE_H_FILES) OBJS=$(C_O_FILES) include $(RTEMS_CUSTOM) -include $(PROJECT_ROOT)/make/lib.cfg +include $(RTEMS_ROOT)/make/lib.cfg # # Add local stuff here using += diff --git a/c/src/lib/libc/syscalls.c b/c/src/lib/libc/syscalls.c index a91ede2446..00c58d9aec 100644 --- a/c/src/lib/libc/syscalls.c +++ b/c/src/lib/libc/syscalls.c @@ -26,6 +26,7 @@ #include /* only for puts */ #include +#include #ifdef RTEMS_NEWLIB /* @@ -35,20 +36,36 @@ int __rtems_fstat(int _fd, struct stat* _sbuf) { - if ( _fd > 2 ) { - puts( "__rtems_fstat -- only stdio supported" ); - assert( 0 ); - } - _sbuf->st_mode = S_IFCHR; #ifdef HAVE_BLKSIZE _sbuf->st_blksize = 0; #endif + + /* + * For now assume stdin/stdout/stderr are always a TTY line + */ + if (_fd <= 2) { + _sbuf->st_mode = S_IFCHR; + } else { + switch (rtems_file_descriptor_type (_fd)) { + case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET: + _sbuf->st_mode = S_IFSOCK; + break; + + default: + puts( "__rtems_fstat -- unknown socket type" ); + assert( 0 ); + } + } return 0; } int __rtems_isatty(int _fd) { - return 1; + struct stat st; + + if (__rtems_fstat(_fd, &st) < 0) + return 0; + return S_ISCHR (st.st_mode); } #if !defined(RTEMS_UNIX) diff --git a/c/src/lib/libc/termios.c b/c/src/lib/libc/termios.c index 8512fd6e14..85e171bd16 100644 --- a/c/src/lib/libc/termios.c +++ b/c/src/lib/libc/termios.c @@ -113,6 +113,7 @@ struct rtems_termios_tty { int (*read)(int minor); int (*write)(int minor, const char *buf, int len); }; + static struct rtems_termios_tty *ttyHead, *ttyTail; static rtems_id ttyMutex; -- cgit v1.2.3