Fixes to allow versionless packages on cd
[minix3.git] / lib / libcompat_minix / fttyslot.c
blob8afb84856b503fbd000cc8125c99d6c7230f7f09
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 #include <sys/types.h>
13 #include <ttyent.h>
14 #include <string.h>
15 #include <unistd.h>
17 int fttyslot(fd)
18 int fd;
20 char *tname;
21 int lineno;
22 struct ttyent *ttyp;
24 tname= ttyname(fd);
25 if (tname == NULL) return 0;
27 /* Assume that tty devices are in /dev */
28 if (strncmp(tname, "/dev/", 5) != 0)
29 return 0; /* Malformed tty name. */
30 tname += 5;
32 /* Scan /etc/ttytab. */
33 lineno= 1;
34 while ((ttyp= getttyent()) != NULL)
36 if (strcmp(tname, ttyp->ty_name) == 0)
38 endttyent();
39 return lineno;
41 lineno++;
43 /* No match */
44 endttyent();
45 return 0;
49 * $PchHeader: /mount/hd2/minix/lib/misc/RCS/ttyslot.c,v 1.3 1994/12/22 13:49:12 philip Exp $