1: /* @(#)ttyname.c 2.1 SCCS id keyword */
2: /*
3: * ttyname(f): return "/dev/ttyXX" which the the name of the
4: * tty belonging to file f.
5: * NULL if it is not a tty
6: */
7:
8: #define NULL 0
9: #include <sys/types.h>
10: #include <sys/dir.h>
11: #include <sys/stat.h>
12:
13: static char dev[] = "/dev/";
14: char *strcpy();
15: char *strcat();
16:
17: char *
18: ttyname(f)
19: {
20: struct stat fsb;
21: struct stat tsb;
22: struct direct db;
23: static char rbuf[32];
24: register df;
25:
26: if (isatty(f)==0)
27: return(NULL);
28: if (fstat(f, &fsb) < 0)
29: return(NULL);
30: if ((fsb.st_mode&S_IFMT) != S_IFCHR)
31: return(NULL);
32: if ((df = open(dev, 0)) < 0)
33: return(NULL);
34: while (read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
35: if (db.d_ino == 0)
36: continue;
37: if (db.d_ino != fsb.st_ino)
38: continue;
39: strcpy(rbuf, dev);
40: strcat(rbuf, db.d_name);
41: if (stat(rbuf, &tsb) < 0)
42: continue;
43: if (tsb.st_dev==fsb.st_dev && tsb.st_ino==fsb.st_ino) {
44: close(df);
45: return(rbuf);
46: }
47: }
48: close(df);
49: return(NULL);
50: }
Defined functions
ttyname
defined in line
17; used 56 times
- in /usr/src/cmd/login.c line
66,
106
- in /usr/src/cmd/mesg.c line
17,
23
- in /usr/src/cmd/pr.c line
47,
158
- in /usr/src/cmd/remind/send.c line
91-93(2)
- in /usr/src/cmd/roff/roff1.s line
6,
125
- in /usr/src/cmd/su.c line
122,
132
- 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/4.2/uucp.h line
266
- in /usr/src/cmd/uucp/DIALUP/uucp.h line
268
- in /usr/src/cmd/uucp/cico.c line
266,
458
- in /usr/src/cmd/uucp/uucp.h line
267
- in /usr/src/cmd/who.c line
19,
34
- in /usr/src/cmd/write.c line
26,
58
- in /usr/src/lib/c/gen/ttyslot.c line
14,
26(3)
- in /usr/src/lib/libU77/ttynam_.c line
22-25(2)
- in /usr/src/local/sroff/s1.c line
309-314(4),
719,
735
- in /usr/src/ucb/delivermail/conf.c line
492-495(4)
- in /usr/src/ucb/delivermail/conf.skel.c line
406-409(4)
- in /usr/src/ucb/ex/ex2/ex.h line
312
- in /usr/src/ucb/ex/ex3/ex.h line
358
- in /usr/src/ucb/ex/ex3/ex_put.c line
937-939(3)
- in /usr/src/ucb/tset/tset.c line
493,
857
Defined variables
dev
defined in line
13; used 2 times
Defined macros
NULL
defined in line
8; used 5 times