Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <sys/mman.h>
  8.  
  9.  
  10. char BUF[100];
  11. int plik1, plik2;
  12. char plik_wym[1000];
  13. char lena[30];
  14. struct stat buffer;
  15. char *ptr;
  16.  
  17. int main()
  18. {
  19.  
  20. if (fork() == 0) //dziecko
  21. {
  22. execlp("display","display","plik_wym", NULL);
  23. }
  24.  
  25.  
  26. while(1)
  27. {
  28. printf("Podaj nazwe pliku: \n");
  29. scanf("%s", lena);
  30.  
  31. plik1=open(lena, O_RDONLY);
  32. plik2=open(plik_wym, O_WRONLY);
  33.  
  34. stat("plik_wym", &buffer);
  35. ftruncate(plik2, buffer.st_size);
  36.  
  37. ptr=mmap(0,buffer.st_size, PROT_WRITE, MAP_SHARED, plik1, 0);
  38. read(plik2, ptr ,buffer.st_size);
  39.  
  40. msync(ptr,buffer.st_size,MS_SYNC);
  41. munmap(ptr, buffer.st_size);
  42. close(plik1);
  43. close(plik2);
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement