new versions which use getttyent(3).
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 28 Apr 1984 01:32:15 +0000 (17:32 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 28 Apr 1984 01:32:15 +0000 (17:32 -0800)
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
usr/src/lib/libc/gen/ttyslot.c

index 339c669..f59dcb9 100644 (file)
@@ -1,4 +1,4 @@
-/*     getlogin.c      4.2     82/11/14        */
+/*     getlogin.c      4.3     84/04/27        */
 
 #include <utmp.h>
 
 
 #include <utmp.h>
 
index b498e49..e0b511a 100644 (file)
@@ -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.
  */
 
 /*
  * 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 <sys/file.h>
+#include <ttyent.h>
 
 char   *ttyname();
 
 char   *ttyname();
-char   *getttys();
 char   *rindex();
 char   *rindex();
-static char    ttys[]  = "/etc/ttys";
 
 #define        NULL    0
 
 ttyslot()
 {
 
 #define        NULL    0
 
 ttyslot()
 {
+       register struct ttyent *ty;
        register char *tp, *p;
        register s, tf;
 
        register char *tp, *p;
        register s, tf;
 
@@ -27,47 +26,15 @@ ttyslot()
                p = tp;
        else
                p++;
                p = tp;
        else
                p++;
-       if ((tf = open(ttys, O_RDONLY)) < 0)
-               return (0);
+       setttyent();
        s = 0;
        s = 0;
-       while (tp = getttys(tf)) {
+       while ((ty = getttyent()) != NULL) {
                s++;
                s++;
-               if (strcmp(p, tp) == 0) {
-                       close(tf);
+               if (strcmp(ty->ty_name, p) == 0) {
+                       endttyent();
                        return (s);
                }
        }
                        return (s);
                }
        }
-       close(tf);
+       endttyent();
        return (0);
 }
        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;
-       }
-}