Compile and execute the following code:
#include <sys/stat.h>
int main()
{
// Create a stat structure for file information
struct stat buf;
// Take away all available rights from file
chmod("foo", 0);
// Give read rights for everyone and and execute right
// for the owner
chmod("foo", S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR);
// Take away read right from other users
stat("foo", &buf);
chmod("foo", buf.st_mode ^ S_IROTH);
// Print current file access rights
stat("foo", &buf);
printf("foo - %4.4o\n", buf.st_mode & 07777);
return 0;
}