Bell 32V development
authorTom London <tbl@research.uucp>
Wed, 29 Nov 1978 04:53:12 +0000 (23:53 -0500)
committerTom London <tbl@research.uucp>
Wed, 29 Nov 1978 04:53:12 +0000 (23:53 -0500)
Work on file usr/src/libc/sys/times.s
Work on file usr/src/libc/gen/ttyname.c

Co-Authored-By: John Reiser <jfr@research.uucp>
Synthesized-from: 32v

usr/src/libc/gen/ttyname.c [new file with mode: 0644]
usr/src/libc/sys/times.s [new file with mode: 0755]

diff --git a/usr/src/libc/gen/ttyname.c b/usr/src/libc/gen/ttyname.c
new file mode 100644 (file)
index 0000000..c7724e0
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * ttyname(f): return "/dev/ttyXX" which the the name of the
+ * tty belonging to file f.
+ *  NULL if it is not a tty
+ */
+
+#define        NULL    0
+#include <sys/types.h>
+#include <sys/dir.h>
+#include <sys/stat.h>
+
+static char    dev[]   = "/dev/";
+char   *strcpy();
+char   *strcat();
+
+char *
+ttyname(f)
+{
+       struct stat fsb;
+       struct stat tsb;
+       struct direct db;
+       static char rbuf[32];
+       register df;
+
+       if (isatty(f)==0)
+               return(NULL);
+       if (fstat(f, &fsb) < 0)
+               return(NULL);
+       if ((fsb.st_mode&S_IFMT) != S_IFCHR)
+               return(NULL);
+       if ((df = open(dev, 0)) < 0)
+               return(NULL);
+       while (read(df, (char *)&db, sizeof(db)) == sizeof(db)) {
+               if (db.d_ino == 0)
+                       continue;
+               if (db.d_ino != fsb.st_ino)
+                       continue;
+               strcpy(rbuf, dev);
+               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);
+                       return(rbuf);
+               }
+       }
+       close(df);
+       return(NULL);
+}
diff --git a/usr/src/libc/sys/times.s b/usr/src/libc/sys/times.s
new file mode 100755 (executable)
index 0000000..c761654
--- /dev/null
@@ -0,0 +1,9 @@
+# C library -- times
+
+       .set    times,43
+.globl _times
+
+_times:
+       .word   0x0000
+       chmk    $times
+       ret