more work
This commit is contained in:
parent
36058cae5f
commit
0f7e29a54d
|
|
@ -3,4 +3,3 @@ execvp.o /z/src/libc/orig_obj/execvp.o differ: char 6, line 1
|
||||||
getgrent.o /z/src/libc/orig_obj/getgrent.o differ: char 132, line 1
|
getgrent.o /z/src/libc/orig_obj/getgrent.o differ: char 132, line 1
|
||||||
malloc.o /z/src/libc/orig_obj/malloc.o differ: char 5, line 1
|
malloc.o /z/src/libc/orig_obj/malloc.o differ: char 5, line 1
|
||||||
nlist.o /z/src/libc/orig_obj/nlist.o differ: char 5, line 1
|
nlist.o /z/src/libc/orig_obj/nlist.o differ: char 5, line 1
|
||||||
ttyname.o /z/src/libc/orig_obj/ttyname.o differ: char 5, line 1
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,7 @@
|
||||||
/*
|
/*
|
||||||
* ttyname(f): return "/dev/ttyXX" which the the name of the
|
* ttyname(f): return "/dev/ttyXX" which the the name of the
|
||||||
* tty belonging to file f.
|
* tty belonging to file f.
|
||||||
*
|
* NULL if it is not a tty
|
||||||
* This program works in two passes: the first pass tries to
|
|
||||||
* find the device by matchine device and inode numbers; if
|
|
||||||
* that doesn't work, it tries a second time, this time doing a
|
|
||||||
* stat on every file in /dev and trying to match device numbers
|
|
||||||
* only. If that fails too, NULL is returned.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
|
|
@ -27,36 +22,30 @@ ttyname(f)
|
||||||
struct stat tsb;
|
struct stat tsb;
|
||||||
struct direct db;
|
struct direct db;
|
||||||
static char rbuf[32];
|
static char rbuf[32];
|
||||||
register df, pass1;
|
register df;
|
||||||
|
|
||||||
if(isatty(f) == 0)
|
if (isatty(f)==0)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
if(fstat(f, &fsb) < 0)
|
if (fstat(f, &fsb) < 0)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
if((fsb.st_mode & S_IFMT) != S_IFCHR)
|
if ((fsb.st_mode&S_IFMT) != S_IFCHR)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
if((df = open(dev, 0)) < 0)
|
if ((df = open(dev, 0)) < 0)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
pass1 = 1;
|
while (read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
|
||||||
do {
|
if (db.d_ino == 0)
|
||||||
while(read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
|
|
||||||
if(db.d_ino == 0)
|
|
||||||
continue;
|
continue;
|
||||||
if(pass1 && db.d_ino != fsb.st_ino)
|
if (db.d_ino != fsb.st_ino)
|
||||||
continue;
|
continue;
|
||||||
strcpy(rbuf, dev);
|
strcpy(rbuf, dev);
|
||||||
strcat(rbuf, db.d_name);
|
strcat(rbuf, db.d_name);
|
||||||
if(stat(rbuf, &tsb) < 0)
|
if (stat(rbuf, &tsb) < 0)
|
||||||
continue;
|
continue;
|
||||||
if(tsb.st_rdev == fsb.st_rdev
|
if (tsb.st_dev==fsb.st_dev && tsb.st_ino==fsb.st_ino) {
|
||||||
&& (tsb.st_mode&S_IFMT) == S_IFCHR
|
|
||||||
&& (!pass1 || tsb.st_ino == fsb.st_ino)) {
|
|
||||||
close(df);
|
close(df);
|
||||||
return(rbuf);
|
return(rbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lseek(df, 0L, 0);
|
|
||||||
} while(pass1--);
|
|
||||||
close(df);
|
close(df);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue