SCCS-vsn: lib/libc/gen/ttyname.c 4.2
-/* @(#)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.
-#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/";
{
struct stat fsb;
struct stat tsb;
{
struct stat fsb;
struct stat tsb;
+ register struct direct *db;
+ register DIR *df;
if (isatty(f)==0)
return(NULL);
if (isatty(f)==0)
return(NULL);
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)
- 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);