summaryrefslogtreecommitdiffstats
path: root/usr.bin/who
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
parent80e0f8337571912ad95e8301d34a3bda6054d911 (diff)
downloadFreeBSD-src-a5eee593ac091b453bd8d7158bf447ab3109b5e8.zip
FreeBSD-src-a5eee593ac091b453bd8d7158bf447ab3109b5e8.tar.gz
Use err(3). Add usage().
Diffstat (limited to 'usr.bin/who')
-rw-r--r--usr.bin/who/who.110
-rw-r--r--usr.bin/who/who.c46
2 files changed, 36 insertions, 20 deletions
diff --git a/usr.bin/who/who.1 b/usr.bin/who/who.1
index 27dc5cd..74e413f 100644
--- a/usr.bin/who/who.1
+++ b/usr.bin/who/who.1
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)who.1 8.2 (Berkeley) 12/30/93
-.\" $Id$
+.\" $Id: who.1,v 1.4 1997/02/22 19:57:52 peter Exp $
.\"
.Dd December 30, 1993
.Dt WHO 1
@@ -43,9 +43,9 @@
.Op Ar am I
.Op Ar file
.Sh DESCRIPTION
-The utility
-.Nm who
-displays
+The
+.Nm
+utility displays
a list of all users currently logged on, showing for each user
the login name,
tty name, the date and time of login, and hostname if not local.
@@ -57,7 +57,7 @@ Available options:
Returns the invoker's real user name.
.It Ar file
By default,
-.Nm who
+.Nm
gathers information from the file
.Pa /var/run/utmp .
An alternate
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