/* a sample program that change the mode of a file */
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>

int main() {
    char filename[80];
    int fildes;
    
    strcpy(filename, "fchmod.c");
    if((fildes = open(filename,O_RDONLY)) == -1){ 
      printf("cannot open file");
      exit(1);
    }
    /* read, write, execute permission: owner 
       read, write permission: group 
       read, write permission: other */
    if(fchmod(fildes,S_IRWXU|         
                      S_IRGRP|S_IWGRP| 
                      S_IROTH|S_IWOTH)!=0)
       printf("can not change the mode of specified file\n");
}
