Guest User

Untitled

a guest
Apr 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf,
  2. size_t buflen, struct passwd **pwbufp);
  3.  
  4. struct passwd pwent;
  5. struct passwd *pwentp;
  6. char buf[1024];
  7.  
  8. if (getpwuid_r(101, &pwent, buf, sizeof buf, &pwentp))
  9. {
  10. perror("getpwuid_r");
  11. }
  12. else
  13. {
  14. printf("Username: %sn", pwent.pw_name);
  15. printf("Real Name: %sn", pwent.pw_gecos);
  16. printf("Home Directory: %sn", pwent.pw_dir);
  17. }
  18.  
  19. struct passwd *getpwuid(uid_t uid);
  20.  
  21. int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp);
  22.  
  23. struct passwd * my_passwd;
  24. my_passwd = getpwuid(uid);
  25. // or:
  26. // my_passwd = getpwnam(username);
  27.  
  28. if (my_passwd == NULL) {
  29. // the lookup failed - handle the error!
  30. } else {
  31. // the lookup succeeded - do your thing
  32. printf("User name: %sn", my_passwd->pw_name);
  33. printf("User password: %sn", my_passwd->pw_passwd);
  34. ...
  35. }
  36.  
  37. int getpwnam_r(const char *name, struct passwd *pwd,
  38. char *buf, size_t buflen, struct passwd **result);
Add Comment
Please, Sign In to add comment