account:password:UID:GID:GECOS:directory:shellThe field descriptions are:
struct passwd { char *pw_name; /* user name */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user id */ gid_t pw_gid; /* group id */ char *pw_gecos; /* real name */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ };
struct utsname {
char sysname[SYS_NMLN];
char nodename[SYS_NMLN];
char release[SYS_NMLN];
char version[SYS_NMLN];
char machine[SYS_NMLN];
#ifdef _GNU_SOURCE
char domainname[SYS_NMLN];
#endif
};
On error, -1 is returned.
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
};
#define h_addr h_addr_list[0] /* for backward compatibility */
#include <stdio.h> #include <sys/types.h> #include <pwd.h> int main(int argc,char *argv[]) { struct passwd *P; while ((P = getpwent()) != NULL) { if (P->pw_uid == geteuid()) { printf("%s\n",P->pw_name); } } return(0); }