Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf,
- size_t buflen, struct passwd **pwbufp);
- struct passwd pwent;
- struct passwd *pwentp;
- char buf[1024];
- if (getpwuid_r(101, &pwent, buf, sizeof buf, &pwentp))
- {
- perror("getpwuid_r");
- }
- else
- {
- printf("Username: %sn", pwent.pw_name);
- printf("Real Name: %sn", pwent.pw_gecos);
- printf("Home Directory: %sn", pwent.pw_dir);
- }
- struct passwd *getpwuid(uid_t uid);
- int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp);
- struct passwd * my_passwd;
- my_passwd = getpwuid(uid);
- // or:
- // my_passwd = getpwnam(username);
- if (my_passwd == NULL) {
- // the lookup failed - handle the error!
- } else {
- // the lookup succeeded - do your thing
- printf("User name: %sn", my_passwd->pw_name);
- printf("User password: %sn", my_passwd->pw_passwd);
- ...
- }
- int getpwnam_r(const char *name, struct passwd *pwd,
- char *buf, size_t buflen, struct passwd **result);
Add Comment
Please, Sign In to add comment