summaryrefslogtreecommitdiffstats
path: root/usr.bin/users
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-22 06:50:33 +0000
committercharnier <charnier@FreeBSD.org>1997-08-22 06:50:33 +0000
commiteaef13799223de597ae84443bde1bd6a34701550 (patch)
tree3aa968e040019441ab78e3128cc9c6657074707e /usr.bin/users
parent0c770f97ecae7439592571f489b1a7baa4f03eba (diff)
downloadFreeBSD-src-eaef13799223de597ae84443bde1bd6a34701550.zip
FreeBSD-src-eaef13799223de597ae84443bde1bd6a34701550.tar.gz
Was limited to 200 users. New entry is now allocated as needed.
Add usage(). Obtained from:OpenBSD.
Diffstat (limited to 'usr.bin/users')
-rw-r--r--usr.bin/users/users.12
-rw-r--r--usr.bin/users/users.c64
2 files changed, 43 insertions, 23 deletions
diff --git a/usr.bin/users/users.1 b/usr.bin/users/users.1
index 57ae2db..04f5c6a 100644
--- a/usr.bin/users/users.1
+++ b/usr.bin/users/users.1
@@ -38,7 +38,7 @@
.Nm users
.Nd list current users
.Sh SYNOPSIS
-.Nm users
+.Nm
.Sh DESCRIPTION
.Nm Users
lists the login names of the users currently on the system,
diff --git a/usr.bin/users/users.c b/usr.bin/users/users.c
index 48a584a..5e5c2bb 100644
--- a/usr.bin/users/users.c
+++ b/usr.bin/users/users.c
@@ -32,57 +32,69 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1980, 1987, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)users.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
-#include <utmp.h>
+#include <err.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <utmp.h>
-#define MAXUSERS 200
+typedef char namebuf[UT_NAMESIZE];
+int scmp __P((const void *, const void *));
+static void usage __P((void));
+
+void
main(argc, argv)
int argc;
char **argv;
{
- extern int optind;
- register int cnt, ncnt;
+ namebuf *names = NULL;
+ int ncnt = 0;
+ int nmax = 0;
+ int cnt;
struct utmp utmp;
- char names[MAXUSERS][UT_NAMESIZE];
- int ch, scmp();
+ int ch;
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
case '?':
default:
- (void)fprintf(stderr, "usage: users\n");
- exit(1);
+ usage();
}
argc -= optind;
argv += optind;
- if (!freopen(_PATH_UTMP, "r", stdin)) {
- (void)fprintf(stderr, "users: can't open %s.\n", _PATH_UTMP);
- exit(1);
- }
- for (ncnt = 0;
- fread((char *)&utmp, sizeof(utmp), 1, stdin) == 1;)
+ if (!freopen(_PATH_UTMP, "r", stdin))
+ errx(1, "can't open %s", _PATH_UTMP);
+ while (fread((char *)&utmp, sizeof(utmp), 1, stdin) == 1) {
if (*utmp.ut_name) {
- if (ncnt == MAXUSERS) {
- (void)fprintf(stderr,
- "users: too many users.\n");
- break;
+ if (ncnt >= nmax) {
+ nmax += 32;
+ names = realloc(names, sizeof (*names) * nmax);
+ if (!names) {
+ errx(1, "realloc");
+ /* NOTREACHED */
+ }
}
(void)strncpy(names[ncnt], utmp.ut_name, UT_NAMESIZE);
++ncnt;
}
-
+ }
if (ncnt) {
qsort(names, ncnt, UT_NAMESIZE, scmp);
(void)printf("%.*s", UT_NAMESIZE, names[0]);
@@ -94,8 +106,16 @@ main(argc, argv)
exit(0);
}
+static void
+usage()
+{
+ (void)fprintf(stderr, "usage: users\n");
+ exit(1);
+}
+
+int
scmp(p, q)
- char *p, *q;
+ const void *p, *q;
{
- return(strncmp(p, q, UT_NAMESIZE));
+ return(strncmp((char *)p, (char *)q, UT_NAMESIZE));
}
OpenPOWER on IntegriCloud