ualarm
[unix-history] / usr / src / lib / libc / gen / ttyslot.c
CommitLineData
b8f253e8
KM
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
2ce81398
DS
7#if defined(LIBC_SCCS) && !defined(lint)
8static char sccsid[] = "@(#)ttyslot.c 5.2 (Berkeley) %G%";
9#endif LIBC_SCCS and not lint
66bba310 10
2bbb9f0d
BJ
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 */
fb7ebc6b 16#include <ttyent.h>
2bbb9f0d
BJ
17
18char *ttyname();
2bbb9f0d 19char *rindex();
2bbb9f0d
BJ
20
21#define NULL 0
22
23ttyslot()
24{
fb7ebc6b 25 register struct ttyent *ty;
2bbb9f0d 26 register char *tp, *p;
cb35684d 27 register s;
2bbb9f0d 28
66bba310
SL
29 if ((tp = ttyname(0)) == NULL &&
30 (tp = ttyname(1)) == NULL &&
31 (tp = ttyname(2)) == NULL)
2bbb9f0d
BJ
32 return(0);
33 if ((p = rindex(tp, '/')) == NULL)
34 p = tp;
35 else
36 p++;
fb7ebc6b 37 setttyent();
2bbb9f0d 38 s = 0;
fb7ebc6b 39 while ((ty = getttyent()) != NULL) {
2bbb9f0d 40 s++;
fb7ebc6b
RC
41 if (strcmp(ty->ty_name, p) == 0) {
42 endttyent();
66bba310 43 return (s);
2bbb9f0d
BJ
44 }
45 }
fb7ebc6b 46 endttyent();
66bba310 47 return (0);
2bbb9f0d 48}