1 /* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)getlogin.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/param.h> 13 #include <pwd.h> 14 #include <utmp.h> 15 #include <stdio.h> 16 #include <string.h> 17 #include <unistd.h> 18 19 int _logname_valid; /* known to setlogin() */ 20 21 char * 22 getlogin() 23 { 24 static char logname[MAXLOGNAME + 1]; 25 26 if (_logname_valid == 0) { 27 if (_getlogin(logname, sizeof(logname) - 1) < 0) 28 return ((char *)NULL); 29 _logname_valid = 1; 30 } 31 return (*logname ? logname : (char *)NULL); 32 } 33