1 /*
2  * getmypwent - return password file entry for invoking user,
3  *	using login name first, if any, then uid.
4  */
5 
6 #include <stdio.h>
7 #include <pwd.h>
8 #include <unistd.h>
9 
10 /* imports */
11 extern char *getlogin();
12 /* extern struct passwd *getpwuid(), *getpwnam(); */
13 
14 /*
15  * Note: this is the canonical way to determine your userid,
16  * as per V7's getlogin(3).  It sure would be nice if everyone
17  * who does only half the job were to do the whole job.
18  */
19 struct passwd *
getmypwent()20 getmypwent()
21 {
22 	register char *login = getlogin();
23 
24 	return login == NULL? getpwuid(getuid()): getpwnam(login);
25 }
26