home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Unix System Administration Handbook 1997 October
/
usah_oct97.iso
/
news
/
cnews.tar
/
inject
/
getmypwent.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-31
|
562b
|
25 lines
/*
* getmypwent - return password file entry for invoking user,
* using login name first, if any, then uid.
*/
#include <stdio.h>
#include <pwd.h>
/* imports */
extern char *getlogin();
/* extern struct passwd *getpwuid(), *getpwnam(); */
/*
* Note: this is the canonical way to determine your userid,
* as per V7's getlogin(3). It sure would be nice if everyone
* who does only half the job were to do the whole job.
*/
struct passwd *
getmypwent()
{
register char *login = getlogin();
return login == NULL? getpwuid(getuid()): getpwnam(login);
}