Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- int main()
- {
- int fd1[2];
- int lacze1=pipe(fd1);
- int fd2[2];
- int lacze2=pipe(fd2);
- int otwierany;
- char blad[]= "Blad";
- char nazwapliku[20];
- char nazwa[20];
- printf("podaj nazwe pliku \n");
- scanf("%s", nazwa);
- char zawartosc[8];
- int potomny=fork();
- switch(potomny)
- {
- case 0:
- read(fd1[0],nazwapliku,10);
- close(fd1[0]);
- otwierany=open(nazwa,"O_RDONLY");
- if(otwierany==-1)
- { write(fd2[1], blad,6);}
- else {
- char bufor[1];
- int bajt;
- bajt=read(otwierany,bufor, 1);
- write(fd2[1],bufor,1);
- while(bajt>0)
- {
- bajt=read(otwierany,bufor, 1);
- write(fd2[1],bufor,1);
- }
- close(fd2[1]);
- }
- break;
- default:
- write(fd1[1],nazwa, 10);
- close(fd1[1]);
- wait();
- read(fd2[0], zawartosc , 8);
- printf("%s \n ", zawartosc);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement