xref: /csrg-svn/lib/libc/gen/ttyslot.c (revision 17880)
1*17880Sralph /* @(#)ttyslot.c	4.4 (Berkeley) 01/30/85 */
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  */
816422Sralph #include <ttyent.h>
91995Swnj 
101995Swnj char	*ttyname();
111995Swnj char	*rindex();
121995Swnj 
131995Swnj #define	NULL	0
141995Swnj 
151995Swnj ttyslot()
161995Swnj {
1716422Sralph 	register struct ttyent *ty;
181995Swnj 	register char *tp, *p;
19*17880Sralph 	register s;
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++;
2916422Sralph 	setttyent();
301995Swnj 	s = 0;
3116422Sralph 	while ((ty = getttyent()) != NULL) {
321995Swnj 		s++;
3316422Sralph 		if (strcmp(ty->ty_name, p) == 0) {
3416422Sralph 			endttyent();
3516277Ssam 			return (s);
361995Swnj 		}
371995Swnj 	}
3816422Sralph 	endttyent();
3916277Ssam 	return (0);
401995Swnj }
41