logname.c revision 331722
1239054Sae/*- 2239054Sae * Copyright (c) 1991, 1993, 1994 3239054Sae * The Regents of the University of California. All rights reserved. 4239054Sae * 5239054Sae * Redistribution and use in source and binary forms, with or without 6239054Sae * modification, are permitted provided that the following conditions 7239054Sae * are met: 8239054Sae * 1. Redistributions of source code must retain the above copyright 9239054Sae * notice, this list of conditions and the following disclaimer. 10239054Sae * 2. Redistributions in binary form must reproduce the above copyright 11239054Sae * notice, this list of conditions and the following disclaimer in the 12239054Sae * documentation and/or other materials provided with the distribution. 13239054Sae * 4. Neither the name of the University nor the names of its contributors 14239054Sae * may be used to endorse or promote products derived from this software 15239054Sae * without specific prior written permission. 16239054Sae * 17239054Sae * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18239054Sae * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19239054Sae * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20239054Sae * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21239054Sae * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22239054Sae * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23239054Sae * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24239054Sae * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25239054Sae * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26239054Sae * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27239054Sae * SUCH DAMAGE. 28239054Sae */ 29239054Sae 30239054Sae#ifndef lint 31239054Saestatic const char copyright[] = 32239054Sae"@(#) Copyright (c) 1991, 1993, 1994\n\ 33239054Sae The Regents of the University of California. All rights reserved.\n"; 34239054Sae#endif /* not lint */ 35239054Sae 36239054Sae#ifndef lint 37239054Saestatic const char sccsid[] = "@(#)logname.c 8.2 (Berkeley) 4/3/94"; 38239054Sae#endif /* not lint */ 39332956Sbenno#include <sys/cdefs.h> 40332956Sbenno__FBSDID("$FreeBSD: stable/11/usr.bin/logname/logname.c 331722 2018-03-29 02:50:57Z eadler $"); 41239054Sae 42239054Sae#include <err.h> 43239054Sae#include <unistd.h> 44239054Sae#include <stdio.h> 45239054Sae#include <stdlib.h> 46239054Sae 47239054Saevoid usage(void); 48239054Sae 49239054Saeint 50239054Saemain(int argc, char *argv[] __unused) 51239054Sae{ 52239054Sae char *p; 53239054Sae 54239054Sae if (argc != 1) 55239054Sae usage(); 56332956Sbenno if ((p = getlogin()) == NULL) 57239054Sae err(1, NULL); 58239054Sae (void)printf("%s\n", p); 59239054Sae exit(0); 60239054Sae} 61239054Sae 62239054Saevoid 63239054Saeusage(void) 64239054Sae{ 65239054Sae (void)fprintf(stderr, "usage: logname\n"); 66239054Sae exit(1); 67329099Skevans} 68300117Simp