Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. //
  2.  
  3. // Created by bartek on 20.11.17.
  4.  
  5. //
  6.  
  7.  
  8.  
  9. #include <stdio.h>
  10.  
  11. #include <unistd.h>
  12.  
  13. #include <sys/types.h>
  14.  
  15. #include <sys/stat.h>
  16.  
  17. #include <sys/mman.h>
  18.  
  19. #include <fcntl.h>
  20.  
  21.  
  22.  
  23. #define image "pies.jpg"
  24.  
  25.  
  26.  
  27.  
  28.  
  29. int main(){
  30.  
  31.  
  32.  
  33.     int fd, file,temp;
  34.  
  35.     int lp;
  36.  
  37.   //char n_pliku[15] = "asfasf";
  38.  
  39.     char buf[128];
  40.  
  41.     struct stat str;
  42.  
  43.     char *mp;
  44.  
  45.  
  46.  
  47.     if(fork() == 0) {
  48.  
  49.     while((temp=open("tmp",O_RDONLY))<0){
  50.  
  51.         sleep(1);
  52.  
  53.     }
  54.  
  55.    
  56.  
  57.         execlp("eog","eog", "tmp", NULL);
  58.  
  59.     close(temp);
  60.  
  61.         exit(-1);
  62.  
  63.     }
  64.  
  65.  
  66.  
  67.        
  68.  
  69.             while (1) {
  70.  
  71.  
  72.  
  73.                 printf("Nazwa pliku do wyswietlenia: ");
  74.  
  75.                 scanf("%s", buf);
  76.  
  77.                 fd = open(buf, O_RDONLY);
  78.  
  79.                 fstat(fd, &str);
  80.  
  81.  
  82.  
  83.                 file = open(image, O_RDWR|O_CREAT, 0666);
  84.  
  85.                 ftruncate(file, str.st_size);
  86.  
  87.  
  88.  
  89.         mp = mmap(0, str.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  90.  
  91.         read(fd,mp,str.st_size);
  92.  
  93.  
  94.  
  95.            
  96.  
  97.                 close(file);
  98.  
  99.                 close(fd);
  100.  
  101.         printf("\n");
  102.  
  103.         }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.     return 0;
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. /*    if(msync(mp, str.st_size, MS_SYNC)<0) {
  120.  
  121.                     int it = 0;
  122.  
  123.                     while ((lp = read(fd, buf, 4096)) > 0) {
  124.  
  125.                         for (int i = 0; i < lp; i++) {
  126.  
  127.                             mp[it] = buf[i];
  128.  
  129.                             it++;
  130.  
  131.                         }
  132.  
  133.  
  134.  
  135.                     }
  136.  
  137.                 }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement