[PATCH] Implement -m for who

From: sin <sin_AT_2f30.org>
Date: Mon, 5 Aug 2013 15:59:49 +0100

---
 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
_AT_@ -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>
_AT_@ -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"))) {
_AT_@ -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
--cWoXeonUoKmBZSoM--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 05 2013 - 17:12:06 CEST