In the signature getpwuid_r:
int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf,
size_t buflen, struct passwd **pwbufp);
uid- The input parameter is the UID of the user you want to find. The rest are essentially output parameters: the structure that it points pwbufto will be filled with password information, and the pointer that it points pwbufpto will be set to pwbufif the call was successful (and NULLif it hadnโt). The pair of parameters bufand buflenindicates the user buffer that is used to store strings, which indicate the members of the structure struct passwdthat are returned.
You would use it like this (this is looking for a user with UID 101):
struct passwd pwent;
struct passwd *pwentp;
char buf[1024];
if (getpwuid_r(101, &pwent, buf, sizeof buf, &pwentp))
{
perror("getpwuid_r");
}
else
{
printf("Username: %s\n", pwent.pw_name);
printf("Real Name: %s\n", pwent.pw_gecos);
printf("Home Directory: %s\n", pwent.pw_dir);
}
, , getpwnam_r pw_uid .