1: #if defined(LIBC_SCCS) && !defined(lint)
2: static char sccsid[] = "@(#)ttyname.c 5.2 (Berkeley) 3/9/86";
3: #endif LIBC_SCCS and not lint
4:
5: /*
6: * ttyname(f): return "/dev/ttyXX" which the the name of the
7: * tty belonging to file f.
8: * NULL if it is not a tty
9: */
10:
11: #define NULL 0
12: #include <sys/param.h>
13: #include <sys/dir.h>
14: #include <sys/stat.h>
15:
16: static char dev[] = "/dev/";
17: char *strcpy();
18: char *strcat();
19:
20: char *
21: ttyname(f)
22: {
23: struct stat fsb;
24: struct stat tsb;
25: register struct direct *db;
26: register DIR *df;
27: static char rbuf[32];
28:
29: if (isatty(f)==0)
30: return(NULL);
31: if (fstat(f, &fsb) < 0)
32: return(NULL);
33: if ((fsb.st_mode&S_IFMT) != S_IFCHR)
34: return(NULL);
35: if ((df = opendir(dev)) == NULL)
36: return(NULL);
37: while ((db = readdir(df)) != NULL) {
38: if (db->d_ino != fsb.st_ino)
39: continue;
40: strcpy(rbuf, dev);
41: strcat(rbuf, db->d_name);
42: if (stat(rbuf, &tsb) < 0)
43: continue;
44: if (tsb.st_dev == fsb.st_dev && tsb.st_ino == fsb.st_ino) {
45: closedir(df);
46: return(rbuf);
47: }
48: }
49: closedir(df);
50: return(NULL);
51: }
Defined functions
ttyname
defined in line
20; used 78 times
- in /usr/ingres/source/qrymod/qrymod.c line
61,
73
- in /usr/src/bin/login.c line
73,
170
- in /usr/src/bin/pr.c line
47,
158
- in /usr/src/bin/ps.c line
166,
298
- in /usr/src/bin/su.c line
104,
111
- in /usr/src/bin/who.c line
35,
50
- in /usr/src/bin/write.c line
29,
64
- in /usr/src/etc/getty/main.c line
56,
133,
427,
437
- in /usr/src/etc/halt.c line
34
- in /usr/src/games/hunt/connect.c line
18-23(2)
- in /usr/src/lib/libc/gen/ttyslot.c line
18,
29-31(3)
- in /usr/src/lib/libc/net/ruserpass.c line
752-756(3)
- in /usr/src/new/X/xterm/main.c line
1115
- in /usr/src/new/jove/jove.c line
52,
438
- in /usr/src/new/kermit/ckutio.c line
360,
386-389(2),
397
- in /usr/src/new/mh/uip/ttym.c line
24-28(2)
- in /usr/src/new/umodem/umodem.c line
240-245(2),
528,
579,
631,
1260
- in /usr/src/old/talk/get_names.c line
14,
51
- in /usr/src/ucb/biff.c line
25,
31
- in /usr/src/ucb/ex/ex.h line
365
- in /usr/src/ucb/ex/ex_put.c line
945-947(3)
- in /usr/src/ucb/lock.c line
40,
87
- in /usr/src/ucb/sysline/sysline.c line
244,
390
- in /usr/src/ucb/talk/get_names.c line
16,
49
- in /usr/src/ucb/tset/tset.c line
548,
937
- in /usr/src/undoc/sps/sps.c line
439-441(2)
- in /usr/src/usr.bin/mesg.c line
18,
24
- in /usr/src/usr.bin/troff/n1.c line
366-371(4),
809,
825
- in /usr/src/usr.bin/tty.c line
6,
13
- in /usr/src/usr.bin/uucp/cico.c line
242,
596
- in /usr/src/usr.bin/uucp/uucp.h line
393-394(2)
- in /usr/src/usr.bin/uucp/vms/uucp.h line
288
- in /usr/src/usr.lib/libU77/ttynam_.c line
28-31(2)
Defined variables
dev
defined in line
16; used 2 times
sccsid
defined in line
2;
never used
Defined macros
NULL
defined in line
11; used 7 times