OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libcsupport/] [src/] [ttyname.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  ttyname_r() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name
3
 *
4
 *  ttyname.c,v 1.7 2002/04/03 14:22:58 joel Exp
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 <string.h>
18
#include <paths.h>
19
#include <_syslist.h>
20
#include <errno.h>
21
 
22
#include <rtems/libio_.h>
23
#include <rtems/seterr.h>
24
 
25
int ttyname_r(
26
  int   fd,
27
  char *name,
28
  int   namesize
29
)
30
{
31
  struct stat sb;
32
  struct termios tty;
33
  struct dirent *dirp;
34
  DIR *dp;
35
  struct stat dsb;
36
  char *rval;
37
 
38
  /* Must be a terminal. */
39
  if (tcgetattr (fd, &tty) < 0)
40
    rtems_set_errno_and_return_minus_one(EBADF);
41
 
42
  /* Must be a character device. */
43
  if (fstat (fd, &sb) || !S_ISCHR (sb.st_mode))
44
    rtems_set_errno_and_return_minus_one(EBADF);
45
 
46
  if ((dp = opendir (_PATH_DEV)) == NULL)
47
    rtems_set_errno_and_return_minus_one(EBADF);
48
 
49
  for (rval = NULL; (dirp = readdir (dp)) != NULL ;)
50
    {
51
      if (dirp->d_ino != sb.st_ino)
52
        continue;
53
      strcpy (name + sizeof (_PATH_DEV) - 1, dirp->d_name);
54
      if (stat (name, &dsb) || sb.st_dev != dsb.st_dev ||
55
          sb.st_ino != dsb.st_ino)
56
        continue;
57
      rval = name;
58
      break;
59
    }
60
  (void) closedir (dp);
61
  return 0;
62
}
63
 
64
static char buf[sizeof (_PATH_DEV) + MAXNAMLEN] = _PATH_DEV;
65
 
66
/*
67
 *  ttyname() - POSIX 1003.1b 4.7.2 - Demetermine Terminal Device Name
68
 */
69
 
70
char *ttyname(
71
  int fd
72
)
73
{
74
  if ( !ttyname_r( fd, buf, sizeof(buf) ) )
75
    return buf;
76
  return NULL;
77
}
78
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.