# 2.11BSD#431 - /usr/src/lib/libc/gen/ttyname.c

##### Functions

    ttyname           X

##### Macros

    NULL              X

       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 74 times

- in /usr/include/unistd.h line 71
- in /usr/ingres/source/qrymod/main.c line 112, 130
- in /usr/src/bin/login/login.c line 101, 171
- in /usr/src/bin/pr.c line 47, 158
- in /usr/src/bin/ps.c line 89, 183, 234
- in /usr/src/bin/su.c line 100, 107
- in /usr/src/bin/tcsh/sh.c line 227
- in /usr/src/bin/tcsh/tc.os.h line 294
- in /usr/src/bin/who.c line 43
- in /usr/src/bin/write.c line 62
- in /usr/src/games/hunt/connect.c line 18-23(2)
- in /usr/src/games/warp/term.c line 288
- in /usr/src/games/warp/warp.h line 456
- in /usr/src/lib/libc/gen/ttyslot.c line 18, 29-31(3)
- in /usr/src/lib/libc/net/ruserpass.c line 755-759(3)
- in /usr/src/libexec/getty/main.c line 54, 132, 418, 428
- in /usr/src/local/welcome/welcome.c line 76
- in /usr/src/new/jove/jove.c line 88, 504
- in /usr/src/new/kermit5.188/ckutio.c line 1017, 1278-1284(4), 1295
- in /usr/src/ucb/biff.c line 25, 31
- in /usr/src/ucb/ex/ex.h line 350
- in /usr/src/ucb/ex/ex_put.c line 927-929(3)
- in /usr/src/ucb/lock/lock.c line 67, 99
- in /usr/src/ucb/talk/get_names.c line 49
- in /usr/src/ucb/tset/tset.c line 649
- in /usr/src/usr.bin/mesg.c line 18, 24
- in /usr/src/usr.bin/roff/common_source/n1.c line 366-371(4), 801, 817
- in /usr/src/usr.bin/tty.c line 6, 13
- in /usr/src/usr.bin/uucp/cico.c line 243, 597
- in /usr/src/usr.lib/libU77/ttynam_.c line 28-31(2)
- in /usr/src/usr.sbin/sendmail.MX/src/conf.c line 259-260(3)
- in /usr/src/usr.sbin/sendmail.MX/src/envelope.c line 239, 279
- in /usr/src/usr.sbin/sendmail/src/conf.c line 259-260(3)
- in /usr/src/usr.sbin/sendmail/src/envelope.c line 233, 273

#### Defined variables

dev defined in line 16; used 2 times

- in line 35-40(2)

sccsid defined in line 2; never used

#### Defined macros

NULL defined in line 11; used 7 times

- in line 30-37(6), 50

Last modified: 1986-03-10 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 734 |