home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / inject / getmypwent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-11  |  556 b   |  25 lines

  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.  
  9. /* imports */
  10. extern char *getlogin();
  11. extern struct passwd *getpwuid(), *getpwnam();
  12.  
  13. /*
  14.  * Note: this is the canonical way to determine your userid,
  15.  * as per V7's getlogin(3).  It sure would be nice if everyone
  16.  * who does only half the job were to do the whole job.
  17.  */
  18. struct passwd *
  19. getmypwent()
  20. {
  21.     register char *login = getlogin();
  22.  
  23.     return login == NULL? getpwuid(getuid()): getpwnam(login);
  24. }
  25.