From c7016198fa34f63e0dd2c8f68443ce2a4170fd79 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 16 Nov 1999 15:27:52 +0000 Subject: Added. --- c/src/exec/libcsupport/src/ctermid.c | 33 +++++++++++++++ c/src/exec/libcsupport/src/tcgetprgrp.c | 33 +++++++++++++++ c/src/exec/libcsupport/src/tcsendbreak.c | 33 +++++++++++++++ c/src/exec/libcsupport/src/tcsetpgrp.c | 33 +++++++++++++++ c/src/exec/libcsupport/src/ttyname.c | 73 ++++++++++++++++++++++++++++++++ c/src/lib/libc/Makefile.in | 7 +-- c/src/lib/libc/ctermid.c | 33 +++++++++++++++ c/src/lib/libc/tcgetprgrp.c | 33 +++++++++++++++ c/src/lib/libc/tcsendbreak.c | 33 +++++++++++++++ c/src/lib/libc/tcsetpgrp.c | 33 +++++++++++++++ c/src/lib/libc/ttyname.c | 73 ++++++++++++++++++++++++++++++++ 11 files changed, 414 insertions(+), 3 deletions(-) create mode 100644 c/src/exec/libcsupport/src/ctermid.c create mode 100644 c/src/exec/libcsupport/src/tcgetprgrp.c create mode 100644 c/src/exec/libcsupport/src/tcsendbreak.c create mode 100644 c/src/exec/libcsupport/src/tcsetpgrp.c create mode 100644 c/src/exec/libcsupport/src/ttyname.c create mode 100644 c/src/lib/libc/ctermid.c create mode 100644 c/src/lib/libc/tcgetprgrp.c create mode 100644 c/src/lib/libc/tcsendbreak.c create mode 100644 c/src/lib/libc/tcsetpgrp.c create mode 100644 c/src/lib/libc/ttyname.c (limited to 'c') diff --git a/c/src/exec/libcsupport/src/ctermid.c b/c/src/exec/libcsupport/src/ctermid.c new file mode 100644 index 0000000000..23308dc4a6 --- /dev/null +++ b/c/src/exec/libcsupport/src/ctermid.c @@ -0,0 +1,33 @@ +/* + * ctermid() - POSIX 1003.1b 4.7.1 - Generate Terminal Pathname + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include + +static ctermid_name = "/dev/console"; + +char *ctermid( + char *s +) +{ + if ( !s ) + return ctermid_name; + + strcpy( s, ctermid_name ); + return s; +} + +#endif diff --git a/c/src/exec/libcsupport/src/tcgetprgrp.c b/c/src/exec/libcsupport/src/tcgetprgrp.c new file mode 100644 index 0000000000..563a1842ed --- /dev/null +++ b/c/src/exec/libcsupport/src/tcgetprgrp.c @@ -0,0 +1,33 @@ +/* + * tcgetprgrp() - POSIX 1003.1b 7.2.3 - Get Foreground Process Group ID + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include +#include +/* #include */ + +int ioctl(); + +#include + +pid_t tcgetprgrp(int fd) +{ + return getpid(); +} + +#endif diff --git a/c/src/exec/libcsupport/src/tcsendbreak.c b/c/src/exec/libcsupport/src/tcsendbreak.c new file mode 100644 index 0000000000..e7da9cf165 --- /dev/null +++ b/c/src/exec/libcsupport/src/tcsendbreak.c @@ -0,0 +1,33 @@ +/* + * tcsendbreak() - POSIX 1003.1b 7.2.2 - Line Control Functions + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include +#include +/* #include */ + +int ioctl(); + +#include + +int tcsendbreak ( int fd, int duration ) +{ + return 0; +} + +#endif diff --git a/c/src/exec/libcsupport/src/tcsetpgrp.c b/c/src/exec/libcsupport/src/tcsetpgrp.c new file mode 100644 index 0000000000..3e6c32c9c4 --- /dev/null +++ b/c/src/exec/libcsupport/src/tcsetpgrp.c @@ -0,0 +1,33 @@ +/* + * tcsetprgrp() - POSIX 1003.1b 7.2.4 - Set Foreground Process Group ID + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include +#include +/* #include */ + +int ioctl(); + +#include + +int tcsetprgrp(int fd, pid_t pid) +{ + return 0; +} + +#endif diff --git a/c/src/exec/libcsupport/src/ttyname.c b/c/src/exec/libcsupport/src/ttyname.c new file mode 100644 index 0000000000..51b3a5f6aa --- /dev/null +++ b/c/src/exec/libcsupport/src/ttyname.c @@ -0,0 +1,73 @@ +/* + * ttyname_r() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include <_syslist.h> +#include + +#include + +int ttyname_r( + int fd, + char *name, + int namesize +) +{ + struct stat sb; + struct termios tty; + struct dirent *dirp; + DIR *dp; + struct stat dsb; + char *rval; + + /* Must be a terminal. */ + if (tcgetattr (fd, &tty) < 0) + set_errno_and_return_minus_one(EBADF); + + /* Must be a character device. */ + if (_fstat (fd, &sb) || !S_ISCHR (sb.st_mode)) + set_errno_and_return_minus_one(EBADF); + + if ((dp = opendir (_PATH_DEV)) == NULL) + set_errno_and_return_minus_one(EBADF); + + for (rval = NULL; (dirp = readdir (dp)) != NULL ;) + { + if (dirp->d_ino != sb.st_ino) + continue; + strcpy (name + sizeof (_PATH_DEV) - 1, dirp->d_name); + if (stat (name, &dsb) || sb.st_dev != dsb.st_dev || + sb.st_ino != dsb.st_ino) + continue; + (void) closedir (dp); + rval = name; + break; + } + (void) closedir (dp); + return 0; +} + +static char buf[sizeof (_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; + +/* + * ttyname() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name + */ + +char *ttyname( + int fd +) +{ + if ( !ttyname_r( fd, buf, sizeof(buf) ) ) + return buf; + return NULL; +} + diff --git a/c/src/lib/libc/Makefile.in b/c/src/lib/libc/Makefile.in index ceba4f7bef..7b3c80ba64 100644 --- a/c/src/lib/libc/Makefile.in +++ b/c/src/lib/libc/Makefile.in @@ -32,13 +32,13 @@ IMFS_C_PIECES = imfs_chown imfs_creat imfs_directory imfs_eval imfs_free \ imfs_fcntl miniimfs_init TERMIOS_C_PIECES = cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcgetattr \ - tcsetattr tcdrain tcflow tcflush termios \ - termiosinitialize termiosreserveresources + tcsetattr tcdrain tcflow tcflush tcgetprgrp tcsendbreak tcsetpgrp \ + termios termiosinitialize termiosreserveresources SYSTEM_CALL_C_PIECES = open close read write lseek ioctl mkdir mknod mkfifo \ rmdir chdir chmod fchmod chown link unlink umask ftruncate utime fstat \ fcntl fpathconf getdents fsync fdatasync pipe dup dup2 symlink readlink \ - creat isatty + creat DIRECTORY_SCAN_C_PIECES = opendir closedir readdir rewinddir scandir seekdir \ telldir getcwd @@ -47,6 +47,7 @@ MALLOC_C_PIECES = malloc __brk __sbrk PASSWORD_GROUP_C_PIECES = getpwent getgrent +TERMINAL_IDENTIFICATION = ctermid isatty ttyname ttyname_r LIBC_GLUE_C_PIECES = __getpid __gettod __times truncate access stat \ lstat pathconf newlibc no_posix no_libc diff --git a/c/src/lib/libc/ctermid.c b/c/src/lib/libc/ctermid.c new file mode 100644 index 0000000000..23308dc4a6 --- /dev/null +++ b/c/src/lib/libc/ctermid.c @@ -0,0 +1,33 @@ +/* + * ctermid() - POSIX 1003.1b 4.7.1 - Generate Terminal Pathname + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include + +static ctermid_name = "/dev/console"; + +char *ctermid( + char *s +) +{ + if ( !s ) + return ctermid_name; + + strcpy( s, ctermid_name ); + return s; +} + +#endif diff --git a/c/src/lib/libc/tcgetprgrp.c b/c/src/lib/libc/tcgetprgrp.c new file mode 100644 index 0000000000..563a1842ed --- /dev/null +++ b/c/src/lib/libc/tcgetprgrp.c @@ -0,0 +1,33 @@ +/* + * tcgetprgrp() - POSIX 1003.1b 7.2.3 - Get Foreground Process Group ID + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include +#include +/* #include */ + +int ioctl(); + +#include + +pid_t tcgetprgrp(int fd) +{ + return getpid(); +} + +#endif diff --git a/c/src/lib/libc/tcsendbreak.c b/c/src/lib/libc/tcsendbreak.c new file mode 100644 index 0000000000..e7da9cf165 --- /dev/null +++ b/c/src/lib/libc/tcsendbreak.c @@ -0,0 +1,33 @@ +/* + * tcsendbreak() - POSIX 1003.1b 7.2.2 - Line Control Functions + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include +#include +/* #include */ + +int ioctl(); + +#include + +int tcsendbreak ( int fd, int duration ) +{ + return 0; +} + +#endif diff --git a/c/src/lib/libc/tcsetpgrp.c b/c/src/lib/libc/tcsetpgrp.c new file mode 100644 index 0000000000..3e6c32c9c4 --- /dev/null +++ b/c/src/lib/libc/tcsetpgrp.c @@ -0,0 +1,33 @@ +/* + * tcsetprgrp() - POSIX 1003.1b 7.2.4 - Set Foreground Process Group ID + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include +#include +/* #include */ + +int ioctl(); + +#include + +int tcsetprgrp(int fd, pid_t pid) +{ + return 0; +} + +#endif diff --git a/c/src/lib/libc/ttyname.c b/c/src/lib/libc/ttyname.c new file mode 100644 index 0000000000..51b3a5f6aa --- /dev/null +++ b/c/src/lib/libc/ttyname.c @@ -0,0 +1,73 @@ +/* + * ttyname_r() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include <_syslist.h> +#include + +#include + +int ttyname_r( + int fd, + char *name, + int namesize +) +{ + struct stat sb; + struct termios tty; + struct dirent *dirp; + DIR *dp; + struct stat dsb; + char *rval; + + /* Must be a terminal. */ + if (tcgetattr (fd, &tty) < 0) + set_errno_and_return_minus_one(EBADF); + + /* Must be a character device. */ + if (_fstat (fd, &sb) || !S_ISCHR (sb.st_mode)) + set_errno_and_return_minus_one(EBADF); + + if ((dp = opendir (_PATH_DEV)) == NULL) + set_errno_and_return_minus_one(EBADF); + + for (rval = NULL; (dirp = readdir (dp)) != NULL ;) + { + if (dirp->d_ino != sb.st_ino) + continue; + strcpy (name + sizeof (_PATH_DEV) - 1, dirp->d_name); + if (stat (name, &dsb) || sb.st_dev != dsb.st_dev || + sb.st_ino != dsb.st_ino) + continue; + (void) closedir (dp); + rval = name; + break; + } + (void) closedir (dp); + return 0; +} + +static char buf[sizeof (_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; + +/* + * ttyname() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name + */ + +char *ttyname( + int fd +) +{ + if ( !ttyname_r( fd, buf, sizeof(buf) ) ) + return buf; + return NULL; +} + -- cgit v1.2.3