utils: Add who from ELKS
authorAlan Cox <alan@linux.intel.com>
Tue, 30 Dec 2014 11:43:12 +0000 (11:43 +0000)
committerAlan Cox <alan@linux.intel.com>
Tue, 30 Dec 2014 11:43:12 +0000 (11:43 +0000)
Applications/util/Makefile
Applications/util/who.c [new file with mode: 0644]

index c71caf0..af2158f 100644 (file)
@@ -88,6 +88,7 @@ SRCS  = banner.c \
        uue.c \
        wc.c \
        which.c \
+       who.c \
        whoami.c \
        write.c \
        xargs.c \
diff --git a/Applications/util/who.c b/Applications/util/who.c
new file mode 100644 (file)
index 0000000..e97a75a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * who.c
+ *
+ * Copyright 1998 Alistair Riddoch
+ * ajr@ecs.soton.ac.uk
+ *
+ * This file may be distributed under the terms of the GNU General Public
+ * License v2, or at your option any later version.
+ */
+
+/*
+ * This is a small version of who for use in the ELKS project.
+ * It is not fully functional, and may not be the most efficient
+ * implementation for larger systems. It minimises memory usage and
+ * code size.
+ */
+
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utmp.h>
+
+void main(int argc, char *argv[])
+{
+    register struct utmp * entry;
+    char * timestr;
+
+    setutent();
+    while ((entry = getutent()) != NULL)
+       if (entry->ut_type == USER_PROCESS) {
+           timestr = ctime(&entry->ut_time);
+           timestr[strlen(timestr) - 1] = '\0';
+           printf("%s  tty%c%c %s %s\n", entry->ut_user,
+                       entry->ut_id[0],
+                       entry->ut_id[1] ? entry->ut_id[1] : 0,
+                       timestr,
+                       entry->ut_host);
+       }
+    exit(0);
+}