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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uC-libc/] [termios/] [ttyname.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
 
2
#include <errno.h>
3
#include <sys/stat.h>
4
#include <dirent.h>
5
 
6
char *
7
ttyname(fd)
8
int   fd;
9
{
10
   static char dev[] = "/dev";
11
   struct stat st, dst;
12
   DIR  *fp;
13
   struct dirent *d;
14
   static char name[NAME_MAX];
15
   int noerr = errno;
16
 
17
   if (fstat(fd, &st) < 0)
18
      return 0;
19
   if (!isatty(fd))
20
   {
21
      errno = ENOTTY;
22
      return 0;
23
   }
24
 
25
   fp = opendir(dev);
26
   if (fp == 0)
27
      return 0;
28
   strcpy(name, dev);
29
   strcat(name, "/");
30
 
31
   while ((d = readdir(fp)) != 0)
32
   {
33
      strcpy(name + sizeof(dev), d->d_name);
34
      if (stat(name, &dst) == 0
35
         && st.st_dev == dst.st_dev && st.st_ino == dst.st_ino)
36
      {
37
         closedir(fp);
38
         errno = noerr;
39
         return name;
40
      }
41
   }
42
   closedir(fp);
43
   errno = noerr;
44
   return 0;
45
}

powered by: WebSVN 2.1.0

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