summaryrefslogtreecommitdiffstats
path: root/usr.bin/rwho
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2013-07-03 20:28:33 +0000
committerpjd <pjd@FreeBSD.org>2013-07-03 20:28:33 +0000
commit09921b0dcb0a6bc73dee2ebaa40efb100a9ba308 (patch)
tree7d2aaaa074510adcfdd241d23c2aba369c455bc6 /usr.bin/rwho
parent4ece8fdc0636ad641f2ac0993501783351e7242e (diff)
downloadFreeBSD-src-09921b0dcb0a6bc73dee2ebaa40efb100a9ba308.zip
FreeBSD-src-09921b0dcb0a6bc73dee2ebaa40efb100a9ba308.tar.gz
Style cleanups.
Submitted by: Mariusz Zaborski <oshogbo@FreeBSD.org> Sponsored by: Google Summer of Code 2013 Reviewed by: pjd MFC after: 1 month
Diffstat (limited to 'usr.bin/rwho')
-rw-r--r--usr.bin/rwho/rwho.c98
1 files changed, 53 insertions, 45 deletions
diff --git a/usr.bin/rwho/rwho.c b/usr.bin/rwho/rwho.c
index 5f1334f..8ae1b3b 100644
--- a/usr.bin/rwho/rwho.c
+++ b/usr.bin/rwho/rwho.c
@@ -1,6 +1,6 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
+/*-
+ * Copyright (c) 1983, 1993 The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -58,22 +58,21 @@ __FBSDID("$FreeBSD$");
#include <timeconv.h>
#include <unistd.h>
-static DIR *dirp;
+#define NUSERS 1000
+#define WHDRSIZE (ssize_t)(sizeof (wd) - sizeof (wd.wd_we))
+/*
+ * this macro should be shared with ruptime.
+ */
+#define down(w,now) ((now) - (w)->wd_recvtime > 11 * 60)
+static DIR *dirp;
static struct whod wd;
-#define NUSERS 1000
+static int nusers;
static struct myutmp {
char myhost[sizeof(wd.wd_hostname)];
int myidle;
struct outmp myutmp;
} myutmp[NUSERS];
-static int nusers;
-
-#define WHDRSIZE (ssize_t)(sizeof (wd) - sizeof (wd.wd_we))
-/*
- * this macro should be shared with ruptime.
- */
-#define down(w,now) ((now) - (w)->wd_recvtime > 11 * 60)
static time_t now;
static int aflg;
@@ -88,17 +87,18 @@ main(int argc, char *argv[])
struct dirent *dp;
int width;
ssize_t cc;
- register struct whod *w = &wd;
- register struct whoent *we;
- register struct myutmp *mp;
+ struct whod *w;
+ struct whoent *we;
+ struct myutmp *mp;
int f, n, i;
int d_first;
+ w = &wd;
(void) setlocale(LC_TIME, "");
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
- while ((ch = getopt(argc, argv, "a")) != -1)
- switch((char)ch) {
+ while ((ch = getopt(argc, argv, "a")) != -1) {
+ switch ((char)ch) {
case 'a':
aflg = 1;
break;
@@ -106,6 +106,7 @@ main(int argc, char *argv[])
default:
usage();
}
+ }
argc -= optind;
argv += optind;
@@ -115,9 +116,9 @@ main(int argc, char *argv[])
if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL)
err(1, "%s", _PATH_RWHODIR);
mp = myutmp;
- (void)time(&now);
- while ((dp = readdir(dirp))) {
- if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5))
+ (void) time(&now);
+ while ((dp = readdir(dirp)) != NULL) {
+ if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5) != 0)
continue;
f = open(dp->d_name, O_RDONLY);
if (f < 0)
@@ -127,22 +128,25 @@ main(int argc, char *argv[])
(void) close(f);
continue;
}
- if (down(w,now)) {
+ if (down(w,now) != 0) {
(void) close(f);
continue;
}
cc -= WHDRSIZE;
we = w->wd_we;
for (n = cc / sizeof (struct whoent); n > 0; n--) {
- if (aflg == 0 && we->we_idle >= 60*60) {
+ if (aflg == 0 && we->we_idle >= 60 * 60) {
we++;
continue;
}
if (nusers >= NUSERS)
errx(1, "too many users");
- mp->myutmp = we->we_utmp; mp->myidle = we->we_idle;
+ mp->myutmp = we->we_utmp;
+ mp->myidle = we->we_idle;
(void) strcpy(mp->myhost, w->wd_hostname);
- nusers++; we++; mp++;
+ nusers++;
+ we++;
+ mp++;
}
(void) close(f);
}
@@ -151,7 +155,9 @@ main(int argc, char *argv[])
width = 0;
for (i = 0; i < nusers; i++) {
/* append one for the blank and use 8 for the out_line */
- int j = strlen(mp->myhost) + 1 + sizeof(mp->myutmp.out_line);
+ int j;
+
+ j = strlen(mp->myhost) + 1 + sizeof(mp->myutmp.out_line);
if (j > width)
width = j;
mp++;
@@ -159,31 +165,33 @@ main(int argc, char *argv[])
mp = myutmp;
for (i = 0; i < nusers; i++) {
char buf[BUFSIZ], cbuf[80];
- time_t t = _int_to_time(mp->myutmp.out_time);
+ time_t t;
+ t = _int_to_time(mp->myutmp.out_time);
strftime(cbuf, sizeof(cbuf),
- d_first ? "%e %b %R" : "%b %e %R",
- localtime(&t));
- (void)sprintf(buf, "%s:%-.*s", mp->myhost,
- (int)sizeof(mp->myutmp.out_line), mp->myutmp.out_line);
+ d_first ? "%e %b %R" : "%b %e %R",
+ localtime(&t));
+ (void) sprintf(buf, "%s:%-.*s", mp->myhost,
+ (int)sizeof(mp->myutmp.out_line), mp->myutmp.out_line);
printf("%-*.*s %-*s %s",
- (int)sizeof(mp->myutmp.out_name),
- (int)sizeof(mp->myutmp.out_name),
- mp->myutmp.out_name,
- width,
- buf,
- cbuf);
+ (int)sizeof(mp->myutmp.out_name),
+ (int)sizeof(mp->myutmp.out_name),
+ mp->myutmp.out_name,
+ width,
+ buf,
+ cbuf);
mp->myidle /= 60;
- if (mp->myidle) {
- if (aflg) {
- if (mp->myidle >= 100*60)
- mp->myidle = 100*60 - 1;
+ if (mp->myidle != 0) {
+ if (aflg != 0) {
+ if (mp->myidle >= 100 * 60)
+ mp->myidle = 100 * 60 - 1;
if (mp->myidle >= 60)
printf(" %2d", mp->myidle / 60);
else
printf(" ");
- } else
+ } else {
printf(" ");
+ }
printf(":%02d", mp->myidle % 60);
}
printf("\n");
@@ -208,12 +216,12 @@ utmpcmp(const void *u1, const void *u2)
int rc;
rc = strncmp(MYUTMP(u1)->myutmp.out_name, MYUTMP(u2)->myutmp.out_name,
- sizeof(MYUTMP(u2)->myutmp.out_name));
- if (rc)
+ sizeof(MYUTMP(u2)->myutmp.out_name));
+ if (rc != 0)
return (rc);
rc = strcmp(MYUTMP(u1)->myhost, MYUTMP(u2)->myhost);
- if (rc)
+ if (rc != 0)
return (rc);
return (strncmp(MYUTMP(u1)->myutmp.out_line, MYUTMP(u2)->myutmp.out_line,
- sizeof(MYUTMP(u2)->myutmp.out_line)));
+ sizeof(MYUTMP(u2)->myutmp.out_line)));
}
OpenPOWER on IntegriCloud