xref: /csrg-svn/lib/libc/gen/ttyslot.c (revision 22122)
1 /*
2  * Copyright (c) 1984 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)ttyslot.c	5.1 (Berkeley) 06/05/85";
9 #endif not lint
10 
11 /*
12  * Return the number of the slot in the utmp file
13  * corresponding to the current user: try for file 0, 1, 2.
14  * Definition is the line number in the /etc/ttys file.
15  */
16 #include <ttyent.h>
17 
18 char	*ttyname();
19 char	*rindex();
20 
21 #define	NULL	0
22 
23 ttyslot()
24 {
25 	register struct ttyent *ty;
26 	register char *tp, *p;
27 	register s;
28 
29 	if ((tp = ttyname(0)) == NULL &&
30 	    (tp = ttyname(1)) == NULL &&
31 	    (tp = ttyname(2)) == NULL)
32 		return(0);
33 	if ((p = rindex(tp, '/')) == NULL)
34 		p = tp;
35 	else
36 		p++;
37 	setttyent();
38 	s = 0;
39 	while ((ty = getttyent()) != NULL) {
40 		s++;
41 		if (strcmp(ty->ty_name, p) == 0) {
42 			endttyent();
43 			return (s);
44 		}
45 	}
46 	endttyent();
47 	return (0);
48 }
49