Fix various functions testing whether a fd looks like it is pointing to a console. Converts dirstat aproaches to checking the tail of fd2path. Reference: /n/sources/patch/applied/isatty Date: Thu Apr 14 15:30:22 CES 2005 --- /sys/src/cmd/ip/telnet.c Thu Apr 14 15:26:04 2005 +++ /sys/src/cmd/ip/telnet.c Thu Apr 14 15:26:01 2005 @@ -504,14 +504,13 @@ static int islikeatty(int fd) { - Dir *d; - int iscons; + char buf[64]; - if((d = dirfstat(fd)) == nil) + if(fd2path(fd, buf, sizeof buf) != 0) return 0; - iscons = (strcmp(d->name, "cons") == 0); - free(d); - return iscons; + + /* might be /mnt/term/dev/cons */ + return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0; } /* --- /sys/src/cmd/rc/plan9.c Thu Apr 14 15:26:16 2005 +++ /sys/src/cmd/rc/plan9.c Thu Apr 14 15:26:13 2005 @@ -561,25 +561,13 @@ int Isatty(int fd) { - Dir *d1, *d2; - int ret; + char buf[64]; - d1 = dirfstat(fd); - if(d1 == nil) + if(fd2path(fd, buf, sizeof buf) != 0) return 0; - if(strncmp(d1->name, "ptty", 4)==0){ /* fwd complaints to philw */ - free(d1); - return 1; - } - d2 = dirstat("/dev/cons"); - if(d2 == nil){ - free(d1); - return 0; - } - ret = (d1->type==d2->type&&d1->dev==d2->dev&&d1->qid.path==d2->qid.path); - free(d1); - free(d2); - return ret; + + /* might be /mnt/term/dev/cons */ + return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0; } void --- /sys/src/cmd/upas/common/libsys.c Thu Apr 14 15:26:32 2005 +++ /sys/src/cmd/upas/common/libsys.c Thu Apr 14 15:26:29 2005 @@ -706,15 +706,13 @@ static int islikeatty(int fd) { - Dir *d; - int rv; + char buf[64]; - d = dirfstat(fd); - if(d == nil) + if(fd2path(fd, buf, sizeof buf) != 0) return 0; - rv = strcmp(d->name, "cons") == 0; - free(d); - return rv; + + /* might be /mnt/term/dev/cons */ + return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0; } extern int --- /sys/src/libstdio/setvbuf.c Thu Apr 14 15:26:49 2005 +++ /sys/src/libstdio/setvbuf.c Thu Apr 14 15:26:47 2005 @@ -40,17 +40,11 @@ static int isatty(int fd) { - Dir *d1, *d2; - int ret; + char buf[64]; - d1 = dirfstat(fd); - d2 = dirstat("/dev/cons"); - ret = 0; - if(d1!=nil && d2!=nil) - ret = (d1->qid.path == d2->qid.path) && - (d1->type == d2->type) && - (d1->dev == d2->dev); - free(d1); - free(d2); - return 0; + if(fd2path(fd, buf, sizeof buf) != 0) + return 0; + + /* might be /mnt/term/dev/cons */ + return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0; }