From fb7ebc6bf1fdb07ac679ba597ff8276eabe12773 Mon Sep 17 00:00:00 2001 From: Ralph Campbell Date: Fri, 27 Apr 1984 17:32:15 -0800 Subject: [PATCH 1/1] new versions which use getttyent(3). SCCS-vsn: lib/libc/gen/ttyslot.c 4.3 SCCS-vsn: lib/libc/gen/getlogin.c 4.3 --- usr/src/lib/libc/gen/getlogin.c | 2 +- usr/src/lib/libc/gen/ttyslot.c | 49 ++++++--------------------------- 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/usr/src/lib/libc/gen/getlogin.c b/usr/src/lib/libc/gen/getlogin.c index 339c669c80..f59dcb98e0 100644 --- a/usr/src/lib/libc/gen/getlogin.c +++ b/usr/src/lib/libc/gen/getlogin.c @@ -1,4 +1,4 @@ -/* getlogin.c 4.2 82/11/14 */ +/* getlogin.c 4.3 84/04/27 */ #include diff --git a/usr/src/lib/libc/gen/ttyslot.c b/usr/src/lib/libc/gen/ttyslot.c index b498e49ae9..e0b511a81e 100644 --- a/usr/src/lib/libc/gen/ttyslot.c +++ b/usr/src/lib/libc/gen/ttyslot.c @@ -1,21 +1,20 @@ -/* @(#)ttyslot.c 4.2 (Berkeley) %G% */ +/* @(#)ttyslot.c 4.3 (Berkeley) %G% */ /* * Return the number of the slot in the utmp file * corresponding to the current user: try for file 0, 1, 2. * Definition is the line number in the /etc/ttys file. */ -#include +#include char *ttyname(); -char *getttys(); char *rindex(); -static char ttys[] = "/etc/ttys"; #define NULL 0 ttyslot() { + register struct ttyent *ty; register char *tp, *p; register s, tf; @@ -27,47 +26,15 @@ ttyslot() p = tp; else p++; - if ((tf = open(ttys, O_RDONLY)) < 0) - return (0); + setttyent(); s = 0; - while (tp = getttys(tf)) { + while ((ty = getttyent()) != NULL) { s++; - if (strcmp(p, tp) == 0) { - close(tf); + if (strcmp(ty->ty_name, p) == 0) { + endttyent(); return (s); } } - close(tf); + endttyent(); return (0); } - -#define BUFSIZ 1024 - -static char * -getttys(f) -{ - static char buf[BUFSIZ + 1], *next = &buf[BUFSIZ + 1]; - register char *lp; - char *start; - - for (;;) { - if (next >= &buf[BUFSIZ]) { - int n = read(f, buf, BUFSIZ); - - if (n <= 0) - return (NULL); - buf[n] = '\0'; - next = &buf[0]; - } - for (lp = next; *lp && *lp != '\n'; lp++) - ; - if (*lp == '\n') { - *lp++ = '\0'; - start = next; - next = lp; - return (start + 2); - } - lseek(f, next - lp, L_INCR); - next = lp; - } -} -- 2.20.1