Advertisement
Guest User

Untitled

a guest
May 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <fcntl.h>
  6.  
  7. // server - preia nume director, trimite # bytes
  8.  
  9. int main() {
  10.  
  11. int f, cod, codW, fW;
  12.  
  13. cod = mkfifo("citire",0666);
  14. codW = mkfifo("scirere",0777);
  15. if(cod<0){
  16. printf("Eroare la creare fifo \n");
  17. exit(2);
  18. }
  19.  
  20. f = open("citire",O_RDONLY);
  21. if(f<0){
  22. printf("Eroare deschidere fifo server \n");
  23. exit(1);
  24. }
  25.  
  26. // citirea din pipe
  27. int i = 0, l;
  28. char c, buf[100];
  29. do{
  30. //citesc un caracter
  31. l=read(f,&c,sizeof(char));
  32. //daca e valid il adaug in sir
  33. if (l>0){
  34. buf[i]=c;
  35. i++;
  36. }
  37. }while (l>0);
  38. buf[i] = 0;
  39. close(f);
  40.  
  41. // contruim comanda shell
  42.  
  43. char command[100] = "du -b ";
  44. strcat(command, buf);
  45.  
  46. FILE* file = popen(command, "r");
  47.  
  48. i = 0;
  49. char result[1000];
  50. while ((c = fgetc(file)) != ' ') { // citim ca din fisier normal, pana la ' '
  51. result[i++] = c;
  52. }
  53.  
  54. fW = open("scriere",O_WRONLY);
  55. write(fW,result,strlen(result));
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement