From 164a2d2d26abff216c9b09fdb3c70b30b6508e4b Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Tue, 30 Mar 1982 20:16:03 -0800 Subject: [PATCH] convert to use new directory access routines SCCS-vsn: lib/libc/gen/ttyname.c 4.2 --- usr/src/lib/libc/gen/ttyname.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/usr/src/lib/libc/gen/ttyname.c b/usr/src/lib/libc/gen/ttyname.c index 34f59f3706..951f79fc95 100644 --- a/usr/src/lib/libc/gen/ttyname.c +++ b/usr/src/lib/libc/gen/ttyname.c @@ -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. @@ -6,8 +6,8 @@ */ #define NULL 0 -#include -#include +#include +#include #include static char dev[] = "/dev/"; @@ -19,9 +19,9 @@ ttyname(f) { struct stat fsb; struct stat tsb; - struct direct db; + register struct direct *db; + register DIR *df; static char rbuf[32]; - register df; if (isatty(f)==0) return(NULL); @@ -29,22 +29,20 @@ ttyname(f) 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); - 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); - strcat(rbuf, db.d_name); + strcat(rbuf, db->d_name); 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); } } - close(df); + closedir(df); return(NULL); } -- 2.20.1