Wednesday, 14 December 2011

Reading man pages

The manual page for getpwuid says, among other things
#include <pwd.h>

struct passwd *getpwuid(uid_t uid);

The passwd structure is defined as follows:

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 */
};

 1. Where is struct passwd defined?

 2. What is uid_t?

 3. Write a minimum C program to print your real name and your user name

SOLUTION
1) A definition for struct passwd is provided by the <pwd.h> header

2) uid_t is a type defined by <sys/types.h> used for numerical user ID


3)


Exercise from: CS3008

No comments: