xref: /original-bsd/usr.bin/logname/logname.c (revision 3705696b)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1991, 1993\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)logname.c	8.1 (Berkeley) 06/09/93";
16 #endif /* not lint */
17 
18 #include <errno.h>
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 main(argc, argv)
25 	int argc;
26 	char *argv[];
27 {
28 	int ch;
29 	char *p;
30 
31 	while ((ch = getopt(argc, argv, "")) != EOF)
32 		switch(ch) {
33 		case '?':
34 		default:
35 			usage();
36 		}
37 	argc -= optind;
38 	argv += optind;
39 
40 	if ((p = getlogin()) == NULL) {
41 		(void)fprintf(stderr, "logname: %s\n", strerror(errno));
42 		exit(1);
43 	}
44 	(void)printf("%s\n", p);
45 	exit(0);
46 }
47 
48 usage()
49 {
50 	(void)fprintf(stderr, "usage: logname\n");
51 	exit(1);
52 }
53