/* a sample program that maps a file to address then
change the access protection of the address. */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

int main() {
    int fildes;
    char *address;
    int len = 10;
    
    fildes = open("mprotect.c",O_RDONLY);
    address = mmap(0, len, PROT_READ, MAP_PRIVATE, fildes, 0);
    printf(" %s \n",address);
    mprotect(address,len,PROT_WRITE); /* change the access protection */
    sprintf(address, " This is a test of mprotect.c");
    printf(" %s \n",address);
    close(fildes);   
}
