#define _POSIX_C_SOURCE 201800 /* same as before */ #include /* getpwuid */ #include /* printf */ int main() { /* If we are interested in the ‹passwd› entry of a particular * user, we don't have to find it ourselves: the function * ‹getpwuid› (and ‹getpwnam›) can find it for us. In this case, * ‹getpwuid› will search by the numeric user id. Let's then * look up our own entry. */ struct passwd *pw = getpwuid( getuid() ); printf( "name: %s\n", pw->pw_name ); printf( "uid: %d\n", pw->pw_uid ); printf( "gid: %d\n", pw->pw_gid ); printf( "home: %s\n", pw->pw_dir ); printf( "shell: %s\n", pw->pw_shell ); printf( "\n" ); } /* Next: ‹getpwnam.c›. */