summaryrefslogtreecommitdiffstats
path: root/usr.bin/finger/finger.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/finger/finger.c')
-rw-r--r--usr.bin/finger/finger.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c
index 5a16765..f4ece3a 100644
--- a/usr.bin/finger/finger.c
+++ b/usr.bin/finger/finger.c
@@ -41,7 +41,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93";
+static char sccsid[] = "@(#)finger.c 8.5 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -58,15 +58,19 @@ static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93";
*/
#include <sys/param.h>
+
+#include <db.h>
+#include <err.h>
+#include <errno.h>
#include <fcntl.h>
-#include <time.h>
#include <pwd.h>
-#include <utmp.h>
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <db.h>
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+
#include "finger.h"
DB *db;
@@ -77,6 +81,7 @@ char tbuf[1024];
static void loginlist __P((void));
static void userlist __P((int, char **));
+int
main(argc, argv)
int argc;
char **argv;
@@ -134,7 +139,7 @@ main(argc, argv)
lflag_print();
else
sflag_print();
- exit(0);
+ return (0);
}
static void
@@ -148,7 +153,7 @@ loginlist()
char name[UT_NAMESIZE + 1];
if (!freopen(_PATH_UTMP, "r", stdin))
- err("%s: %s", _PATH_UTMP, strerror(errno));
+ err(1, "%s", _PATH_UTMP);
name[UT_NAMESIZE] = NULL;
while (fread((char *)&user, sizeof(user), 1, stdin) == 1) {
if (!user.ut_name[0])
@@ -163,12 +168,15 @@ loginlist()
}
if (db && lflag)
for (sflag = R_FIRST;; sflag = R_NEXT) {
+ PERSON *tmp;
+
r = (*db->seq)(db, &key, &data, sflag);
if (r == -1)
- err("db seq: %s", strerror(errno));
+ err(1, "db seq");
if (r == 1)
break;
- enter_lastlog(*(PERSON **)data.data);
+ memmove(&tmp, data.data, sizeof tmp);
+ enter_lastlog(tmp);
}
}
@@ -186,7 +194,7 @@ userlist(argc, argv)
if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL ||
(used = calloc(argc, sizeof(int))) == NULL)
- err("%s", strerror(errno));
+ err(1, NULL);
/* Pull out all network requests. */
for (ap = p = argv, np = nargv; *p; ++p)
@@ -207,13 +215,13 @@ userlist(argc, argv)
*/
if (mflag)
for (p = argv; *p; ++p)
- if (pw = getpwnam(*p))
+ if ((pw = getpwnam(*p)) != NULL)
enter_person(pw);
else
(void)fprintf(stderr,
"finger: %s: no such user\n", *p);
else {
- while (pw = getpwent())
+ while ((pw = getpwent()) != NULL)
for (p = argv, ip = used; *p; ++p, ++ip)
if (match(pw, *p)) {
enter_person(pw);
@@ -237,7 +245,7 @@ net: for (p = nargv; *p;)
* appropriate data whenever a match occurs.
*/
if (!freopen(_PATH_UTMP, "r", stdin))
- err("%s: %s", _PATH_UTMP, strerror(errno));
+ err(1, "%s", _PATH_UTMP);
while (fread((char *)&user, sizeof(user), 1, stdin) == 1) {
if (!user.ut_name[0])
continue;
@@ -247,11 +255,14 @@ net: for (p = nargv; *p;)
}
if (db)
for (sflag = R_FIRST;; sflag = R_NEXT) {
+ PERSON *tmp;
+
r = (*db->seq)(db, &key, &data, sflag);
if (r == -1)
- err("db seq: %s", strerror(errno));
+ err(1, "db seq");
if (r == 1)
break;
- enter_lastlog(*(PERSON **)data.data);
+ memmove(&tmp, data.data, sizeof tmp);
+ enter_lastlog(tmp);
}
}
OpenPOWER on IntegriCloud