the window strings is NOT quoted at this point; other cleanups
[unix-history] / usr / src / lib / libc / gen / ttyname.c
index 34f59f3..a7dabea 100644 (file)
@@ -1,4 +1,7 @@
-/* @(#)ttyname.c       4.1 (Berkeley) %G% */
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ttyname.c  5.2 (Berkeley) %G%";
+#endif LIBC_SCCS and not lint
+
 /*
  * 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,7 +9,7 @@
  */
 
 #define        NULL    0
  */
 
 #define        NULL    0
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/dir.h>
 #include <sys/stat.h>
 
 #include <sys/dir.h>
 #include <sys/stat.h>
 
@@ -19,9 +22,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 +32,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);
 }