(who): New arg OPTIONS. All uses changed.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 30 Mar 2005 05:24:05 +0000 (05:24 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 30 Mar 2005 05:24:05 +0000 (05:24 +0000)
(main): Check PIDs when invoked with zero or two arguments.
Omit duplicate code in 2-arg case.
(UT_PID): Moved to ../lib/readutmp.h.

src/who.c

index c69285f..3d9d023 100644 (file)
--- a/src/who.c
+++ b/src/who.c
 #define IDLESTR_LEN 6
 
 #if HAVE_STRUCT_XTMP_UT_PID
-# define UT_PID(U) ((U)->ut_pid)
 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
   char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
   sprintf (Var, "%ld", (long int) (Utmp_ent->ut_pid))
 #else
-# define UT_PID(U) 0
 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
   const char *Var = ""
 #endif
@@ -607,14 +605,15 @@ scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
     }
 }
 
-/* Display a list of who is on the system, according to utmp file filename. */
+/* Display a list of who is on the system, according to utmp file FILENAME.
+   Use read_utmp OPTIONS to read the file.  */
 static void
-who (const char *filename)
+who (const char *filename, int options)
 {
   size_t n_users;
   STRUCT_UTMP *utmp_buf;
 
-  if (read_utmp (filename, &n_users, &utmp_buf) != 0)
+  if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
     error (EXIT_FAILURE, errno, "%s", filename);
 
   if (short_list)
@@ -811,18 +810,16 @@ main (int argc, char **argv)
 
   switch (argc - optind)
     {
+    case 2:                    /* who <blurf> <glop> */
+      my_line_only = true;
+      /* Fall through.  */
     case -1:
     case 0:                    /* who */
-      who (UTMP_FILE);
+      who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
       break;
 
     case 1:                    /* who <utmp file> */
-      who (argv[optind]);
-      break;
-
-    case 2:                    /* who <blurf> <glop> */
-      my_line_only = true;
-      who (UTMP_FILE);
+      who (argv[optind], 0);
       break;
 
     default:                   /* lose */