[PATCH 1/3] Implement -m for who

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

---
 who.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/who.c b/who.c
index ae969d6..756363e 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(STDIN_FILENO), '/') + 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);
_AT_@ -36,6 +49,5 @@ main(int argc, char **argv)
 void
 usage(void)
 {
-	eprintf("usage: who\n");
+	eprintf("usage: who [-m]\n");
 }
-
-- 
1.8.3.4
--gKMricLos+KVdGMg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="0002-No-need-to-cast-to-char.patch"
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 06 2013 - 11:00:03 CEST