Uninitialized vector entry?
[minix3.git] / lib / other / ttyslot.c
bloba3e9c98d456b3a6ea3f29067b93802bd8c9411e0
1 /*
2 ttyslot.c
4 Return the index in the utmp file for the current user's terminal. The
5 current user's terminal is the first file descriptor in the range 0..2
6 for which ttyname() returns a name. The index is the line number in the
7 /etc/ttytab file. 0 will be returned in case of an error.
9 Created: Oct 11, 1992 by Philip Homburg
12 #define _MINIX_SOURCE
14 #include <sys/types.h>
15 #include <ttyent.h>
16 #include <string.h>
17 #include <unistd.h>
19 int ttyslot()
21 int slot;
23 slot= fttyslot(0);
24 if (slot == 0) slot= fttyslot(1);
25 if (slot == 0) slot= fttyslot(2);
26 return slot;
29 int fttyslot(fd)
30 int fd;
32 char *tname;
33 int lineno;
34 struct ttyent *ttyp;
36 tname= ttyname(fd);
37 if (tname == NULL) return 0;
39 /* Assume that tty devices are in /dev */
40 if (strncmp(tname, "/dev/", 5) != 0)
41 return 0; /* Malformed tty name. */
42 tname += 5;
44 /* Scan /etc/ttytab. */
45 lineno= 1;
46 while ((ttyp= getttyent()) != NULL)
48 if (strcmp(tname, ttyp->ty_name) == 0)
50 endttyent();
51 return lineno;
53 lineno++;
55 /* No match */
56 endttyent();
57 return 0;
61 * $PchHeader: /mount/hd2/minix/lib/misc/RCS/ttyslot.c,v 1.3 1994/12/22 13:49:12 philip Exp $