137086Skfall /* 2*61111Sbostic * Copyright (c) 1988, 1993 3*61111Sbostic * The Regents of the University of California. All rights reserved. 437086Skfall * 542624Sbostic * %sccs.include.redist.c% 637086Skfall */ 737086Skfall 826558Sdonn #if defined(LIBC_SCCS) && !defined(lint) 9*61111Sbostic static char sccsid[] = "@(#)getlogin.c 8.1 (Berkeley) 06/04/93"; 1037086Skfall #endif /* LIBC_SCCS and not lint */ 119193Ssam 1243654Skarels #include <sys/param.h> 1337086Skfall #include <pwd.h> 149109Ssam #include <utmp.h> 1546597Sdonn #include <stdio.h> 1646597Sdonn #include <string.h> 1746597Sdonn #include <unistd.h> 189109Ssam 1938789Skarels int _logname_valid; /* known to setlogin() */ 209109Ssam 219109Ssam char * getlogin()229109Ssamgetlogin() 239109Ssam { 2443654Skarels static char logname[MAXLOGNAME + 1]; 259109Ssam 2638789Skarels if (_logname_valid == 0) { 2738789Skarels if (_getlogin(logname, sizeof(logname) - 1) < 0) 2838789Skarels return ((char *)NULL); 2938789Skarels _logname_valid = 1; 309193Ssam } 3138789Skarels return (*logname ? logname : (char *)NULL); 329109Ssam } 33