source: rtems/c/src/lib/libc/ttyname.c @ b449267

4.104.114.84.95
Last change on this file since b449267 was a02224e, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 18:29:37

2002-01-04 Ralf Corsepius <corsepiu@…>

  • include/rtems/libio_.h: Remove set_errno_and_return_minus_one.
  • libc/cfsetispeed.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/cfsetospeed.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chown.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/chroot.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/closedir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/eval.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fchdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fchmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fdatasync.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fpathconf.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fstat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/fsync.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ftruncate.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/getdents.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ioctl.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/link.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/lseek.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/mknod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/open.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/read.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/readlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/rmdir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/stat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/symlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/tcsetattr.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/telldir.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ttyname.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/ttyname_r.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/unlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/unmount.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/utime.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • libc/write.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 *  ttyname_r() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name
3 *
4 *  $Id$
5 */
6
7#if HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <sys/types.h>
12#include <sys/stat.h>
13#include <fcntl.h>
14#include <dirent.h>
15#include <termios.h>
16#include <unistd.h>
17#include <paths.h>
18#include <_syslist.h>
19#include <errno.h>
20
21#include <rtems/libio_.h>
22#include <rtems/seterr.h>
23
24int ttyname_r(
25  int   fd,
26  char *name,
27  int   namesize
28)
29{
30  struct stat sb;
31  struct termios tty;
32  struct dirent *dirp;
33  DIR *dp;
34  struct stat dsb;
35  char *rval;
36
37  /* Must be a terminal. */
38  if (tcgetattr (fd, &tty) < 0)
39    rtems_set_errno_and_return_minus_one(EBADF);
40
41  /* Must be a character device. */
42  if (fstat (fd, &sb) || !S_ISCHR (sb.st_mode))
43    rtems_set_errno_and_return_minus_one(EBADF);
44
45  if ((dp = opendir (_PATH_DEV)) == NULL)
46    rtems_set_errno_and_return_minus_one(EBADF);
47
48  for (rval = NULL; (dirp = readdir (dp)) != NULL ;)
49    {
50      if (dirp->d_ino != sb.st_ino)
51        continue;
52      strcpy (name + sizeof (_PATH_DEV) - 1, dirp->d_name);
53      if (stat (name, &dsb) || sb.st_dev != dsb.st_dev ||
54          sb.st_ino != dsb.st_ino)
55        continue;
56      rval = name;
57      break;
58    }
59  (void) closedir (dp);
60  return 0;
61}
62
63static char buf[sizeof (_PATH_DEV) + MAXNAMLEN] = _PATH_DEV;
64
65/*
66 *  ttyname() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name
67 */
68
69char *ttyname(
70  int fd
71)
72{
73  if ( !ttyname_r( fd, buf, sizeof(buf) ) )
74    return buf;
75  return NULL;
76}
77
Note: See TracBrowser for help on using the repository browser.