ttyslot speedup for login, wall, passwd
eric j. haug
ejh at slu70.UUCP
Thu Feb 7 10:31:45 AEST 1985
Subject: ttyslot speedup
Index: <src/lib/c/gen>/<ttyslot.c> 2.9bsd
Description:
A subfunction of ttyslot reads /etc/ttys a character at a time,
using a system call per character.
Repeat-By:
Observation.
Fix:
How about ....
Side effect -- slightly larger versions of login, wall, and passwd.
*** ttyslot.c~ Wed Feb 6 17:56:55 1985
--- ttyslot.c Wed Feb 6 16:51:57 1985
***************
*** 27,28
register char *tp, *p;
register s, tf;
--- 27,29 -----
register char *tp, *p;
+ #ifdef SLOWGETTTYS
register s, tf;
***************
*** 28,29
register s, tf;
--- 29,34 -----
register s, tf;
+ #else
+ register s;
+ FILE *tf;
+ #endif
***************
*** 35,36
p++;
if ((tf=open(ttys, 0)) < 0)
--- 40,42 -----
p++;
+ #ifdef SLOWGETTTYS
if ((tf=open(ttys, 0)) < 0)
***************
*** 36,37
if ((tf=open(ttys, 0)) < 0)
return(0);
--- 42,46 -----
if ((tf=open(ttys, 0)) < 0)
+ #else
+ if ((tf=fopen(ttys, "r")) == (FILE *)NULL)
+ #endif
return(0);
***************
*** 41,42
if (strcmp(p, tp)==0) {
close(tf);
--- 50,52 -----
if (strcmp(p, tp)==0) {
+ #ifdef SLOWGETTTYS
close(tf);
***************
*** 42,43
close(tf);
return(s);
--- 52,56 -----
close(tf);
+ #else
+ fclose(tf);
+ #endif
return(s);
***************
*** 45,46
}
close(tf);
--- 58,60 -----
}
+ #ifdef SLOWGETTTYS
close(tf);
***************
*** 46,47
close(tf);
return(0);
--- 60,64 -----
close(tf);
+ #else
+ fclose(tf);
+ #endif
return(0);
***************
*** 48,49
}
static char *
--- 65,67 -----
}
+ #ifdef SLOWGETTTYS
static char *
***************
*** 74
}
--- 92,117 -----
}
+ #else
+
+ static char *
+ getttys(f)
+ FILE *f;
+ {
+ static char line[DIRSIZ + 4];
+ register char *lp;
+ register char *lb;
+ char lbuf[132];
+
+ lp = line;
+ lb = lbuf;
+ fgets(lbuf, sizeof(lbuf), f);
+ if ( feof(f) || ferror(f) )
+ return((char *)NULL);
+ while (!(*lb=='\t'||*lb==' '||*lb=='\n'||lp >= &line[sizeof(line)]))
+ *lp++ = *lb++;
+ *lp = '\000';
+ if ( lp <= &line[2])
+ return((char *)NULL);
+ else
+ return(&line[2]);
+ }
+ #endif
More information about the Comp.bugs.2bsd
mailing list