NetBSD/usr.bin/users/users.c

107 lines
3.0 KiB
C
Raw Normal View History

/* $NetBSD: users.c,v 1.13 2004/01/05 23:23:37 jmmv Exp $ */
1993-03-21 12:45:37 +03:00
/*
* Copyright (c) 1980, 1987, 1993
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
1993-03-21 12:45:37 +03:00
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1980, 1987, 1993\n\
The Regents of the University of California. All rights reserved.\n");
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)users.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: users.c,v 1.13 2004/01/05 23:23:37 jmmv Exp $");
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
2002-08-02 03:51:20 +04:00
#include <time.h>
1993-03-21 12:45:37 +03:00
#include <stdio.h>
#include <stdlib.h>
1994-12-20 18:58:19 +03:00
#include <string.h>
#include <unistd.h>
1993-03-21 12:45:37 +03:00
2002-08-02 03:51:20 +04:00
#include "utmpentry.h"
1993-03-21 12:45:37 +03:00
int main __P((int, char **));
1994-12-20 18:58:19 +03:00
int
1993-03-21 12:45:37 +03:00
main(argc, argv)
int argc;
char **argv;
{
int ncnt = 0;
1994-12-20 18:58:19 +03:00
int ch;
2002-08-02 03:51:20 +04:00
struct utmpentry *from, *ehead, *save, **nextp;
1993-03-21 12:45:37 +03:00
while ((ch = getopt(argc, argv, "")) != -1)
1993-03-21 12:45:37 +03:00
switch(ch) {
case '?':
default:
(void)fprintf(stderr, "usage: %s\n", getprogname());
1993-03-21 12:45:37 +03:00
exit(1);
}
argc -= optind;
argv += optind;
2002-08-02 03:51:20 +04:00
ncnt = getutentries(NULL, &ehead);
if (ncnt == 0)
return 0;
2002-08-02 03:51:20 +04:00
from = ehead;
ehead = NULL;
while (from != NULL) {
for (nextp = &ehead;
(*nextp) && strcmp(from->name, (*nextp)->name) > 0;
nextp = &(*nextp)->next)
continue;
save = from;
from = from->next;
save->next = *nextp;
*nextp = save;
}
2002-08-02 03:51:20 +04:00
save = ehead;
(void)printf("%s", ehead->name);
2002-08-02 03:51:20 +04:00
for (from = ehead->next; from; from = from->next)
if (strcmp(save->name, from->name) != 0) {
(void)printf(" %s", from->name);
save = from;
1993-03-21 12:45:37 +03:00
}
2002-08-02 03:51:20 +04:00
(void)printf("\n");
1993-03-21 12:45:37 +03:00
exit(0);
}