Research V5 development
authorDennis Ritchie <dmr@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
committerDennis Ritchie <dmr@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
Work on file usr/source/s2/who.c

Co-Authored-By: Ken Thompson <ken@research.uucp>
Synthesized-from: v5

usr/source/s2/who.c [new file with mode: 0644]

diff --git a/usr/source/s2/who.c b/usr/source/s2/who.c
new file mode 100644 (file)
index 0000000..9afe286
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * who
+ */
+
+int    fout;
+int    buf[256];
+
+main(argc, argv)
+char **argv;
+{
+       char *s, *cbuf;
+       int n, fi, i;
+       struct {
+               char name[8];
+               char tty;
+               char pad1;
+               int time[2];
+               char pad2[2];
+       } *p;
+
+       s = "/etc/utmp";
+       if(argc > 1)
+               s = argv[1];
+       fi = open(s, 0);
+       if(fi < 0) {
+               write("cannot open wtmp\n", 17);
+               exit();
+       }
+       fout = dup(1);
+       close(1);
+
+loop:
+       n = read(fi, buf, 512);
+       if(n == 0) {
+               flush();
+               exit();
+       }
+
+       p = &buf;
+       for(p = &buf; (n =- 16)>=0; p++) {
+               if(p->name[0] == '\0' && argc==1)
+                       continue;
+               for(i=0; i<8; i++) {
+                       if(p->name[i] == '\0')
+                               p->name[i] = ' ';
+                       putchar(p->name[i]);
+               }
+               for(i=0; i<3; i++)
+                       putchar("tty"[i]);
+               putchar(p->tty);
+               cbuf = ctime(p->time);
+               for(i=3; i<16; i++)
+                       putchar(cbuf[i]);
+               putchar('\n');
+       }
+       goto loop;
+}