Getpwuid
Define the function: struct passwd * getpwuid (uid_t UID );
Function Description: getpwuid () is used to search for the user identification code specified by the UID parameter one by one. When it is found, the user's data is returned in a structure. For details about the structure, refer to the passwd structure for the user data.
. For the passwd structure, see getpwent ().
The Return Value Returns the passwd structure data. If the return value is null, it indicates that no data exists or there is an error.
Error.
The passwd structure related to system data is defined as follows:
Struct passwd
{
Char * pw_name;/* User name */
Char * pw_passwd;/* password .*/
_ Uid_t pw_uid;/* User ID .*/
_ Gid_t pw_gid;/* Group ID .*/
Char * pw_gecos;/* real name */
Char * pw_dir;/* main directory .*/
Char * pw_shell;/* shell used */
};
Instance:
# Include <PWD. h>
# Include <sys/types. h>
Main ()
{
Struct passwd * user;
User = getpwuid (6 );
Printf ("Name: % s \ n", user-> pw_name );
Printf ("uid: % d \ n", user-> pw_uid );
Printf ("Home: % s \ n", user-> pw_dir );
}