]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/Extras/libg/ttynum.c
Updated documentation and comments about sendmail/pipe.
[nmh] / docs / historical / mh-jun-1982 / Extras / libg / ttynum.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "../h/stat.h"
9
10 ttynum(name)
11 char *name;
12 {
13 /* this routine returns the internal number */
14 /* of the given tty name (string) */
15 /* if the name="tty" or "", the number is that */
16 /* of the user's tty. */
17 /* this is obviously very system dependent */
18 register int major, minor, flags;
19 struct inode ibuf;
20 struct { char low, high; };
21
22 if (*name == '\0' || equal(name,"tty")) {
23 if (fstat(2,&ibuf) < 0 &&
24 fstat(1,&ibuf) < 0) return(-1);
25 }
26 else
27 if (stat(cat("/dev/",name),&ibuf) < 0 &&
28 stat(cat("/dev/tty",name),&ibuf) < 0) return(-1);
29 flags = ibuf.i_mode;
30 if ((flags & IFMT) != IFCHR) return(-1);
31 minor = ibuf.i_addr[0].low;
32 major = ibuf.i_addr[0].high;
33 if (major == 0)
34 return(minor);
35 else
36 if (major == 1)
37 return(minor+1);
38 else
39 return (-1);
40 }