source: trunk/minix/lib/other/ttyslot.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.1 KB
Line 
1/*
2ttyslot.c
3
4Return the index in the utmp file for the current user's terminal. The
5current user's terminal is the first file descriptor in the range 0..2
6for 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.
8
9Created: Oct 11, 1992 by Philip Homburg
10*/
11
12#define _MINIX_SOURCE
13
14#include <sys/types.h>
15#include <ttyent.h>
16#include <string.h>
17#include <unistd.h>
18
19int ttyslot()
20{
21 int slot;
22
23 slot= fttyslot(0);
24 if (slot == 0) slot= fttyslot(1);
25 if (slot == 0) slot= fttyslot(2);
26 return slot;
27}
28
29int fttyslot(fd)
30int fd;
31{
32 char *tname;
33 int lineno;
34 struct ttyent *ttyp;
35
36 tname= ttyname(fd);
37 if (tname == NULL) return 0;
38
39 /* Assume that tty devices are in /dev */
40 if (strncmp(tname, "/dev/", 5) != 0)
41 return 0; /* Malformed tty name. */
42 tname += 5;
43
44 /* Scan /etc/ttytab. */
45 lineno= 1;
46 while ((ttyp= getttyent()) != NULL)
47 {
48 if (strcmp(tname, ttyp->ty_name) == 0)
49 {
50 endttyent();
51 return lineno;
52 }
53 lineno++;
54 }
55 /* No match */
56 endttyent();
57 return 0;
58}
59
60/*
61 * $PchHeader: /mount/hd2/minix/lib/misc/RCS/ttyslot.c,v 1.3 1994/12/22 13:49:12 philip Exp $
62 */
Note: See TracBrowser for help on using the repository browser.