|
|
1.1 root 1: /*
2: * Return the number of the slot in the utmp file
3: * corresponding to the current user.
4: * Definition is the line number in the /etc/ttys file.
5: */
6:
7: extern char *cttyname();
8: extern char *strcpy();
9:
10: static char *
11: getttys(f)
12: {
13: static char line[32];
14: register char *lp;
15:
16: lp = line;
17: for (;;) {
18: if (read(f, lp, 1) != 1) {
19: return(0);
20: }
21: if (*lp =='\n') {
22: *lp = '\0';
23: return(line+2);
24: }
25: if (lp >= &line[32]) {
26: return(line+2);
27: }
28: lp++;
29: }
30: }
31:
32: extern int
33: pttyslot()
34: {
35: register char *cp, *tp;
36: int s, tf;
37:
38: if ((cp = cttyname()) == 0)
39: return(0);
40: if (strncmp(cp, "/dev/", 5) == 0)
41: cp += 5;
42: if ((tf=open("/etc/ttys", 0)) < 0)
43: return(0);
44: s = 0;
45: while (tp = getttys(tf)) {
46: s++;
47: if (strcmp(cp, tp)==0) {
48: close(tf);
49: return(s);
50: }
51: }
52: close(tf);
53: return(-s);
54: }
55:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.