Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by bartek on 20.11.17.
- //
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- #define image "pies.jpg"
- int main(){
- int fd, file,temp;
- int lp;
- //char n_pliku[15] = "asfasf";
- char buf[128];
- struct stat str;
- char *mp;
- if(fork() == 0) {
- while((temp=open("tmp",O_RDONLY))<0){
- sleep(1);
- }
- execlp("eog","eog", "tmp", NULL);
- close(temp);
- exit(-1);
- }
- while (1) {
- printf("Nazwa pliku do wyswietlenia: ");
- scanf("%s", buf);
- fd = open(buf, O_RDONLY);
- fstat(fd, &str);
- file = open(image, O_RDWR|O_CREAT, 0666);
- ftruncate(file, str.st_size);
- mp = mmap(0, str.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- read(fd,mp,str.st_size);
- close(file);
- close(fd);
- printf("\n");
- }
- return 0;
- }
- /* if(msync(mp, str.st_size, MS_SYNC)<0) {
- int it = 0;
- while ((lp = read(fd, buf, 4096)) > 0) {
- for (int i = 0; i < lp; i++) {
- mp[it] = buf[i];
- it++;
- }
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement