Facebook
From Chocolate Hummingbird, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 167
  1. #include <sys/mman.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <sys/types.h>
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.   char *addr;
  12.   char *mfile = "lena.jpg";
  13.   char infile[64];
  14.   int fd01, fd02;
  15.   pid_t pid;
  16.  
  17.   struct stat st;
  18.  
  19.   fd01 = open(mfile, O_RDWR);
  20.  
  21.   stat(mfile, &st);
  22.  
  23.   addr = (char*)mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd01, 0);
  24.  
  25.   pid = fork();
  26.  
  27.   if(pid == 0)
  28.   {
  29.     execlp("display", "display","-update","2", mfile, 0 );
  30.         //execlp("display", "display", "-update", "2", "MAP.jpg", NULL);
  31.   }
  32.   else
  33.   {
  34.     while(1)
  35.     {
  36.       gets(infile);
  37.       fd02 = open(mfile, O_RDONLY);
  38.       stat(fd02, &st);
  39.       ftruncate(fd02, st.st_size);
  40.       addr = (char*)mmap(addr, st.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd02, 0);
  41.       read(fd02, addr, st.st_size);
  42.       msync(addr, st.st_size, 0);
  43.       close(fd02);
  44.     }
  45.   }
  46.  
  47.   munmap(addr, st.st_size);
  48.   close(fd01);
  49.  
  50.  
  51.   return 0;
  52. }
  53.