1: /*
2: * ttyname(f): return "/dev/ttyXX" which the the name of the
3: * tty belonging to file f.
4: * NULL if it is not a tty
5: */
6:
7: #define NULL 0
8: #include <sys/types.h>
9: #include <sys/dir.h>
10: #include <sys/stat.h>
11:
12: static char dev[] = "/dev/";
13: char *strcpy();
14: char *strcat();
15:
16: char *
17: ttyname(f)
18: {
19: struct stat fsb;
20: struct stat tsb;
21: struct direct db;
22: static char rbuf[32];
23: register df;
24:
25: if (isatty(f)==0)
26: return(NULL);
27: if (fstat(f, &fsb) < 0)
28: return(NULL);
29: if ((fsb.st_mode&S_IFMT) != S_IFCHR)
30: return(NULL);
31: if ((df = open(dev, 0)) < 0)
32: return(NULL);
33: while (read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
34: if (db.d_ino == 0)
35: continue;
36: if (db.d_ino != fsb.st_ino)
37: continue;
38: strcpy(rbuf, dev);
39: strcat(rbuf, db.d_name);
40: if (stat(rbuf, &tsb) < 0)
41: continue;
42: if (tsb.st_dev==fsb.st_dev && tsb.st_ino==fsb.st_ino) {
43: close(df);
44: return(rbuf);
45: }
46: }
47: close(df);
48: return(NULL);
49: }
Defined functions
ttyname
defined in line
16; used 26 times
- in /usr/src/cmd/login.c line
26,
51
- in /usr/src/cmd/mesg.c line
17,
23
- in /usr/src/cmd/pr.c line
41,
127
- in /usr/src/cmd/roff/roff1.s line
6,
125
- in /usr/src/cmd/troff/n1.c line
348-353(4),
770,
786
- in /usr/src/cmd/tty.c line
5,
12
- in /usr/src/cmd/uucp/cico.c line
52,
299
- in /usr/src/cmd/who.c line
12,
23
- in /usr/src/cmd/write.c line
20,
46
- in /usr/src/libc/gen/ttyslot.c line
8,
20(3)
Defined variables
dev
defined in line
12; used 2 times
Defined macros
NULL
defined in line
7; used 5 times