convert to use new directory access routines
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Wed, 31 Mar 1982 04:16:03 +0000 (20:16 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Wed, 31 Mar 1982 04:16:03 +0000 (20:16 -0800)
SCCS-vsn: lib/libc/gen/ttyname.c 4.2

usr/src/lib/libc/gen/ttyname.c

index 34f59f3..951f79f 100644 (file)
@@ -1,4 +1,4 @@
-/* @(#)ttyname.c       4.1 (Berkeley) %G% */
+/* @(#)ttyname.c       4.2 (Berkeley) %G% */
 /*
  * ttyname(f): return "/dev/ttyXX" which the the name of the
  * tty belonging to file f.
 /*
  * ttyname(f): return "/dev/ttyXX" which the the name of the
  * tty belonging to file f.
@@ -6,8 +6,8 @@
  */
 
 #define        NULL    0
  */
 
 #define        NULL    0
-#include <sys/types.h>
-#include <sys/dir.h>
+#include <sys/param.h>
+#include <sys/ndir.h>
 #include <sys/stat.h>
 
 static char    dev[]   = "/dev/";
 #include <sys/stat.h>
 
 static char    dev[]   = "/dev/";
@@ -19,9 +19,9 @@ ttyname(f)
 {
        struct stat fsb;
        struct stat tsb;
 {
        struct stat fsb;
        struct stat tsb;
-       struct direct db;
+       register struct direct *db;
+       register DIR *df;
        static char rbuf[32];
        static char rbuf[32];
-       register df;
 
        if (isatty(f)==0)
                return(NULL);
 
        if (isatty(f)==0)
                return(NULL);
@@ -29,22 +29,20 @@ ttyname(f)
                return(NULL);
        if ((fsb.st_mode&S_IFMT) != S_IFCHR)
                return(NULL);
                return(NULL);
        if ((fsb.st_mode&S_IFMT) != S_IFCHR)
                return(NULL);
-       if ((df = open(dev, 0)) < 0)
+       if ((df = opendir(dev)) == NULL)
                return(NULL);
                return(NULL);
-       while (read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
-               if (db.d_ino == 0)
-                       continue;
-               if (db.d_ino != fsb.st_ino)
+       while ((db = readdir(df)) != NULL) {
+               if (db->d_ino != fsb.st_ino)
                        continue;
                strcpy(rbuf, dev);
                        continue;
                strcpy(rbuf, dev);
-               strcat(rbuf, db.d_name);
+               strcat(rbuf, db->d_name);
                if (stat(rbuf, &tsb) < 0)
                        continue;
                if (stat(rbuf, &tsb) < 0)
                        continue;
-               if (tsb.st_dev==fsb.st_dev && tsb.st_ino==fsb.st_ino) {
-                       close(df);
+               if (tsb.st_dev == fsb.st_dev && tsb.st_ino == fsb.st_ino) {
+                       closedir(df);
                        return(rbuf);
                }
        }
                        return(rbuf);
                }
        }
-       close(df);
+       closedir(df);
        return(NULL);
 }
        return(NULL);
 }