1 /*- 2 * Copyright (c) 1991, 1993, 1994 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, 1994\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.2 (Berkeley) 04/03/94"; 16 #endif /* not lint */ 17 18 #include <err.h> 19 #include <errno.h> 20 #include <unistd.h> 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include <string.h> 24 25 void usage __P((void)); 26 27 int 28 main(argc, argv) 29 int argc; 30 char *argv[]; 31 { 32 int ch; 33 char *p; 34 35 while ((ch = getopt(argc, argv, "")) != EOF) 36 switch (ch) { 37 case '?': 38 default: 39 usage(); 40 } 41 argc -= optind; 42 argv += optind; 43 44 if ((p = getlogin()) == NULL) 45 err(1, NULL); 46 (void)printf("%s\n", p); 47 exit(0); 48 } 49 50 void 51 usage() 52 { 53 (void)fprintf(stderr, "usage: logname\n"); 54 exit(1); 55 } 56