#define _POSIX_C_SOURCE 201800 /* as before */ #include /* getpwnam */ #include /* printf */ /* This program prints the basic information about a user whose * login name is given to it as a command-line argument. */ int main( int argc, const char **argv ) { if ( argc != 2 ) /* check command line arguments */ { fputs( "expected 1 username as an argument\n", stderr ); return 1; } /* Like ‹getpwuid›, the ‹getpwnam› function looks up user * records, but this time by their login (user name). */ struct passwd *pw = getpwnam( argv[1] ); 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" ); return 0; } /* Next: ‹getgrent.c›. */