xref: /csrg-svn/lib/libc/gen/ttyslot.c (revision 42627)
1 /*
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)ttyslot.c	5.5 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <ttyent.h>
13 #include <stdio.h>
14 
15 ttyslot()
16 {
17 	register struct ttyent *ttyp;
18 	register int slot;
19 	register char *p;
20 	int cnt;
21 	char *name, *rindex(), *ttyname();
22 
23 	setttyent();
24 	for (cnt = 0; cnt < 3; ++cnt)
25 		if (name = ttyname(cnt)) {
26 			if (p = rindex(name, '/'))
27 				++p;
28 			else
29 				p = name;
30 			for (slot = 1; ttyp = getttyent(); ++slot)
31 				if (!strcmp(ttyp->ty_name, p)) {
32 					endttyent();
33 					return(slot);
34 				}
35 			break;
36 		}
37 	endttyent();
38 	return(0);
39 }
40