+/* For some options, process the wtmp file to generate output */
+static void
+process_wtmp(FILE *fp)
+{
+ struct utmp ut;
+ struct utmp lboot_ut = { "", "", "", 0 };
+ int num = 0; /* count of user entries */
+
+ while (fread(&ut, sizeof(ut), 1, fp) == 1)
+ if (*ut.ut_name != '\0') {
+ if (bflag && (!strcmp(ut.ut_name, "reboot"))) {
+ memcpy(&lboot_ut, &ut, sizeof(ut));
+ }
+ else
+ num++;
+ };
+
+ if (bflag && (!strcmp(lboot_ut.ut_name, "reboot")))
+ row(&lboot_ut);
+
+ /* run level of the init process is unknown in BSD system. If multi
+ user, then display the highest run level. Else, no-op.
+ */
+ if (rflag && (num > 1))
+ printf(" . run-level 3\n");
+}
+
+static void
+quick(FILE *fp)
+{
+ struct utmp ut;
+ int col, ncols, num;
+
+ ncols = ttywidth();
+ col = num = 0;
+ while (fread(&ut, sizeof(ut), 1, fp) == 1) {
+ if (*ut.ut_name == '\0')
+ continue;
+ printf("%-*.*s", UT_NAMESIZE, UT_NAMESIZE, ut.ut_name);
+ if (++col < ncols / (UT_NAMESIZE + 1))
+ putchar(' ');
+ else {
+ col = 0;
+ putchar('\n');
+ }
+ num++;
+ }
+ if (col != 0)
+ putchar('\n');