home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / inject / getmypwent.c < prev    next >
C/C++ Source or Header  |  1994-01-31  |  562b  |  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.