Hi,

Implemented -m for who.  No manpage update yet.

Thanks,
sin
>From ae65cd3af60fafd309a5c84c6c79a157354d4a02 Mon Sep 17 00:00:00 2001
From: sin <s...@2f30.org>
Date: Mon, 5 Aug 2013 15:59:49 +0100
Subject: [PATCH] Implement -m for who

---
 who.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/who.c b/who.c
index ae969d6..3d0c5db 100644
--- a/who.c
+++ b/who.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <time.h>
 #include <utmp.h>
@@ -15,8 +16,17 @@ main(int argc, char **argv)
        FILE *ufp;
        time_t t;
        char timebuf[sizeof "yyyy-mm-dd hh:mm"];
+       bool mflag = false;
 
-       if(argc!=1)
+       ARGBEGIN {
+       case 'm':
+               mflag = true;
+               break;
+       default:
+               usage();
+       } ARGEND;
+
+       if (argc > 0)
                usage();
 
        if (!(ufp = fopen(_PATH_UTMP, "r"))) {
@@ -25,6 +35,9 @@ main(int argc, char **argv)
        while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) {
                if (!*usr.ut_name || !*usr.ut_line)
                        continue;
+               if (mflag && strcmp(usr.ut_line,
+                                   strrchr(ttyname(0), '/') + 1))
+                       continue;
                t = usr.ut_time;
                strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", 
localtime(&t));
                printf("%-8s %-12s %-16s\n", usr.ut_name, usr.ut_line, timebuf);
-- 
1.8.2.3

Reply via email to