summaryrefslogtreecommitdiffstats
path: root/usr.bin/who/who.c
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-26 11:14:57 +0000
committercharnier <charnier@FreeBSD.org>1997-08-26 11:14:57 +0000
commita5eee593ac091b453bd8d7158bf447ab3109b5e8 (patch)
treea1be46ae1d588bfaeaf291fd1b413bd037ef0950 /usr.bin/who/who.c
parent80e0f8337571912ad95e8301d34a3bda6054d911 (diff)
downloadFreeBSD-src-a5eee593ac091b453bd8d7158bf447ab3109b5e8.zip
FreeBSD-src-a5eee593ac091b453bd8d7158bf447ab3109b5e8.tar.gz
Use err(3). Add usage().
Diffstat (limited to 'usr.bin/who/who.c')
-rw-r--r--usr.bin/who/who.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/usr.bin/who/who.c b/usr.bin/who/who.c
index e16a7b9..13b6552 100644
--- a/usr.bin/who/who.c
+++ b/usr.bin/who/who.c
@@ -35,23 +35,34 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)who.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <sys/file.h>
-#include <time.h>
+#include <err.h>
+#include <locale.h>
#include <pwd.h>
-#include <utmp.h>
#include <stdio.h>
-#include <locale.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+static void usage __P((void));
+void output __P((struct utmp *));
+
+int
main(argc, argv)
int argc;
char **argv;
@@ -60,7 +71,7 @@ main(argc, argv)
struct utmp usr;
struct passwd *pw;
FILE *ufp, *file();
- char *t, *rindex(), *strcpy(), *strncpy(), *ttyname();
+ char *t;
(void) setlocale(LC_TIME, "");
@@ -82,9 +93,9 @@ main(argc, argv)
ufp = file(_PATH_UTMP);
/* search through the utmp and find an entry for this tty */
- if (p = ttyname(0)) {
+ if ((p = ttyname(0))) {
/* strip any directory component */
- if (t = rindex(p, '/'))
+ if ((t = rindex(p, '/')))
p = t + 1;
while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1)
if (*usr.ut_name && !strcmp(usr.ut_line, p)) {
@@ -102,12 +113,21 @@ main(argc, argv)
output(&usr);
break;
default:
- (void)fprintf(stderr, "usage: who [ file ]\n who am i\n");
- exit(1);
+ usage();
}
exit(0);
}
+static void
+usage()
+{
+ (void)fprintf(stderr, "%s\n%s\n",
+ "usage: who [file]",
+ " who am i");
+ exit(1);
+}
+
+void
output(up)
struct utmp *up;
{
@@ -127,13 +147,9 @@ FILE *
file(name)
char *name;
{
- extern int errno;
FILE *ufp;
- char *strerror();
- if (!(ufp = fopen(name, "r"))) {
- (void)fprintf(stderr, "who: %s: %s.\n", name, strerror(errno));
- exit(1);
- }
+ if (!(ufp = fopen(name, "r")))
+ err(1, "%s", name);
return(ufp);
}
OpenPOWER on IntegriCloud