xref: /csrg-svn/lib/libc/gen/ttyslot.c (revision 17880)
1 /* @(#)ttyslot.c	4.4 (Berkeley) 01/30/85 */
2 
3 /*
4  * Return the number of the slot in the utmp file
5  * corresponding to the current user: try for file 0, 1, 2.
6  * Definition is the line number in the /etc/ttys file.
7  */
8 #include <ttyent.h>
9 
10 char	*ttyname();
11 char	*rindex();
12 
13 #define	NULL	0
14 
15 ttyslot()
16 {
17 	register struct ttyent *ty;
18 	register char *tp, *p;
19 	register s;
20 
21 	if ((tp = ttyname(0)) == NULL &&
22 	    (tp = ttyname(1)) == NULL &&
23 	    (tp = ttyname(2)) == NULL)
24 		return(0);
25 	if ((p = rindex(tp, '/')) == NULL)
26 		p = tp;
27 	else
28 		p++;
29 	setttyent();
30 	s = 0;
31 	while ((ty = getttyent()) != NULL) {
32 		s++;
33 		if (strcmp(ty->ty_name, p) == 0) {
34 			endttyent();
35 			return (s);
36 		}
37 	}
38 	endttyent();
39 	return (0);
40 }
41