add Berkeley specific header; written by Sam Leffler
[unix-history] / usr / src / lib / libc / gen / ttyslot.c
... / ...
CommitLineData
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#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)ttyslot.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and 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
18char *ttyname();
19char *rindex();
20
21#define NULL 0
22
23ttyslot()
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}