xref: /csrg-svn/lib/libc/gen/ttyslot.c (revision 16422)
1*16422Sralph /* @(#)ttyslot.c	4.3 (Berkeley) 04/27/84 */
216277Ssam 
31995Swnj /*
41995Swnj  * Return the number of the slot in the utmp file
51995Swnj  * corresponding to the current user: try for file 0, 1, 2.
61995Swnj  * Definition is the line number in the /etc/ttys file.
71995Swnj  */
8*16422Sralph #include <ttyent.h>
91995Swnj 
101995Swnj char	*ttyname();
111995Swnj char	*rindex();
121995Swnj 
131995Swnj #define	NULL	0
141995Swnj 
151995Swnj ttyslot()
161995Swnj {
17*16422Sralph 	register struct ttyent *ty;
181995Swnj 	register char *tp, *p;
191995Swnj 	register s, tf;
201995Swnj 
2116277Ssam 	if ((tp = ttyname(0)) == NULL &&
2216277Ssam 	    (tp = ttyname(1)) == NULL &&
2316277Ssam 	    (tp = ttyname(2)) == NULL)
241995Swnj 		return(0);
251995Swnj 	if ((p = rindex(tp, '/')) == NULL)
261995Swnj 		p = tp;
271995Swnj 	else
281995Swnj 		p++;
29*16422Sralph 	setttyent();
301995Swnj 	s = 0;
31*16422Sralph 	while ((ty = getttyent()) != NULL) {
321995Swnj 		s++;
33*16422Sralph 		if (strcmp(ty->ty_name, p) == 0) {
34*16422Sralph 			endttyent();
3516277Ssam 			return (s);
361995Swnj 		}
371995Swnj 	}
38*16422Sralph 	endttyent();
3916277Ssam 	return (0);
401995Swnj }
41