xref: /csrg-svn/lib/libc/gen/ttyslot.c (revision 22122)
1*22122Smckusick /*
2*22122Smckusick  * Copyright (c) 1984 Regents of the University of California.
3*22122Smckusick  * All rights reserved.  The Berkeley software License Agreement
4*22122Smckusick  * specifies the terms and conditions for redistribution.
5*22122Smckusick  */
616277Ssam 
7*22122Smckusick #ifndef lint
8*22122Smckusick static char sccsid[] = "@(#)ttyslot.c	5.1 (Berkeley) 06/05/85";
9*22122Smckusick #endif not lint
10*22122Smckusick 
111995Swnj /*
121995Swnj  * Return the number of the slot in the utmp file
131995Swnj  * corresponding to the current user: try for file 0, 1, 2.
141995Swnj  * Definition is the line number in the /etc/ttys file.
151995Swnj  */
1616422Sralph #include <ttyent.h>
171995Swnj 
181995Swnj char	*ttyname();
191995Swnj char	*rindex();
201995Swnj 
211995Swnj #define	NULL	0
221995Swnj 
231995Swnj ttyslot()
241995Swnj {
2516422Sralph 	register struct ttyent *ty;
261995Swnj 	register char *tp, *p;
2717880Sralph 	register s;
281995Swnj 
2916277Ssam 	if ((tp = ttyname(0)) == NULL &&
3016277Ssam 	    (tp = ttyname(1)) == NULL &&
3116277Ssam 	    (tp = ttyname(2)) == NULL)
321995Swnj 		return(0);
331995Swnj 	if ((p = rindex(tp, '/')) == NULL)
341995Swnj 		p = tp;
351995Swnj 	else
361995Swnj 		p++;
3716422Sralph 	setttyent();
381995Swnj 	s = 0;
3916422Sralph 	while ((ty = getttyent()) != NULL) {
401995Swnj 		s++;
4116422Sralph 		if (strcmp(ty->ty_name, p) == 0) {
4216422Sralph 			endttyent();
4316277Ssam 			return (s);
441995Swnj 		}
451995Swnj 	}
4616422Sralph 	endttyent();
4716277Ssam 	return (0);
481995Swnj }
49