summaryrefslogtreecommitdiff
path: root/libc/termios/ttyname.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-09 20:06:30 +0000
commitc1fe19d4c1db610692365472a90f4661e48449c1 (patch)
treed0b0219ffca3c4c4256f55c4aea4513e43d6aecd /libc/termios/ttyname.c
parent9efafb8bbc7408b04643dcd53825d971577b4d9d (diff)
Bug ugly formatting update
Diffstat (limited to 'libc/termios/ttyname.c')
-rw-r--r--libc/termios/ttyname.c66
1 files changed, 31 insertions, 35 deletions
diff --git a/libc/termios/ttyname.c b/libc/termios/ttyname.c
index 9fc4f950c..ee78137c0 100644
--- a/libc/termios/ttyname.c
+++ b/libc/termios/ttyname.c
@@ -4,43 +4,39 @@
#include <sys/stat.h>
#include <dirent.h>
-char *
-ttyname(fd)
-int fd;
+char *ttyname(fd)
+int fd;
{
- static char dev[] = "/dev";
- struct stat st, dst;
- DIR *fp;
- struct dirent *d;
- static char name[NAME_MAX];
- int noerr = errno;
+ static char dev[] = "/dev";
+ struct stat st, dst;
+ DIR *fp;
+ struct dirent *d;
+ static char name[NAME_MAX];
+ int noerr = errno;
- if (fstat(fd, &st) < 0)
- return 0;
- if (!isatty(fd))
- {
- errno = ENOTTY;
- return 0;
- }
+ if (fstat(fd, &st) < 0)
+ return 0;
+ if (!isatty(fd)) {
+ errno = ENOTTY;
+ return 0;
+ }
- fp = opendir(dev);
- if (fp == 0)
- return 0;
- strcpy(name, dev);
- strcat(name, "/");
+ fp = opendir(dev);
+ if (fp == 0)
+ return 0;
+ strcpy(name, dev);
+ strcat(name, "/");
- while ((d = readdir(fp)) != 0)
- {
- strcpy(name + sizeof(dev), d->d_name);
- if (stat(name, &dst) == 0
- && st.st_dev == dst.st_dev && st.st_ino == dst.st_ino)
- {
- closedir(fp);
- errno = noerr;
- return name;
- }
- }
- closedir(fp);
- errno = noerr;
- return 0;
+ while ((d = readdir(fp)) != 0) {
+ strcpy(name + sizeof(dev), d->d_name);
+ if (stat(name, &dst) == 0
+ && st.st_dev == dst.st_dev && st.st_ino == dst.st_ino) {
+ closedir(fp);
+ errno = noerr;
+ return name;
+ }
+ }
+ closedir(fp);
+ errno = noerr;
+ return 0;
}