137086Skfall /* 237086Skfall * Copyright (c) 1988 The Regents of the University of California. 337086Skfall * All rights reserved. 437086Skfall * 542624Sbostic * %sccs.include.redist.c% 637086Skfall */ 737086Skfall 826558Sdonn #if defined(LIBC_SCCS) && !defined(lint) 9*46597Sdonn static char sccsid[] = "@(#)getlogin.c 5.9 (Berkeley) 02/23/91"; 1037086Skfall #endif /* LIBC_SCCS and not lint */ 119193Ssam 1243654Skarels #include <sys/param.h> 1337086Skfall #include <pwd.h> 149109Ssam #include <utmp.h> 15*46597Sdonn #include <stdio.h> 16*46597Sdonn #include <string.h> 17*46597Sdonn #include <unistd.h> 189109Ssam 1938789Skarels int _logname_valid; /* known to setlogin() */ 209109Ssam 219109Ssam char * 229109Ssam getlogin() 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 } 3337086Skfall 3437086Skfall char * 3537086Skfall cuserid(s) 3638789Skarels char *s; 3737086Skfall { 3837086Skfall register struct passwd *pwd; 3937086Skfall 4037460Sbostic if ((pwd = getpwuid(geteuid())) == NULL) { 4137460Sbostic if (s) 4237086Skfall *s = '\0'; 4338789Skarels return (s); 4437086Skfall } 4537460Sbostic if (s) { 4637460Sbostic (void)strncpy(s, pwd->pw_name, L_cuserid); 4738789Skarels return (s); 4837086Skfall } 4938789Skarels return (pwd->pw_name); 5037086Skfall } 51