1*37398Sbostic #include <pwd.h>
2*37398Sbostic extern struct passwd *getpwuid();
3*37398Sbostic extern char *getlogin();
4*37398Sbostic extern char *getenv();
5*37398Sbostic 
6*37398Sbostic char *
7*37398Sbostic logname()
8*37398Sbostic {
9*37398Sbostic 	register struct passwd *pw;
10*37398Sbostic 	register char *cp;
11*37398Sbostic 
12*37398Sbostic 	cp = getenv("USER");
13*37398Sbostic 	if (cp != 0 && *cp != '\0')
14*37398Sbostic 		return (cp);
15*37398Sbostic 	cp = getlogin();
16*37398Sbostic 	if (cp != 0 && *cp != '\0')
17*37398Sbostic 		return (cp);
18*37398Sbostic 	setpwent();
19*37398Sbostic 	pw=getpwuid(getuid());
20*37398Sbostic 	endpwent();
21*37398Sbostic 	return(pw->pw_name);
22*37398Sbostic }
23