NoPaste.me

Secure and Anonymous

Login

  • Only for Administration!
Time 28.06.2011 - 16:14
Code Language C++
This paste is public Public
Show Options
  1. //Demonstration of named pipes
  2. //Write opens a pipe then it writes into the pipe
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. //Pipe call
  7. #include <fcntl.h>
  8. //mknod call
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11.  
  12. #define BUFLEN 100
  13.  
  14. //Prototypes
  15.  
  16. int main (void);
  17. void input(char *);
  18.  
  19. //Var's
  20.  
  21. //Filedescritpor
  22. int fdes;
  23. int a,i;
  24. char *s, buffer[BUFLEN];
  25.  
  26. int main(void)
  27. {
  28. /*
  29. Creates a  FIFO-File with the rights read/write
  30. for the user and read for others.
  31. */
  32. mknod("pipe1",S_IFIFO | 0666,0);
  33.  
  34. /*
  35. Opens a pipe. This process can only write into a pipe. If its opend successfull open() gives the filedescriptor back otherwise -1.
  36. */
  37. if((fdes=open("pipe1",O_WRONLY))==-1){
  38. puts("Error couldn't open pipe");
  39. exit(-1);
  40. }
  41.  
  42. //Writes the buffer into the FIFO file
  43. input(buffer);
  44. if((i=write(fdes,buffer,BUFLEN)) !=BUFLEN) {
  45. printf("Error couldn't write");
  46. exit(-1);
  47. }
  48.  
  49. //Now we have to close the FIFO File
  50. close(fdes);
  51. exit(0);
  52. }
  53.  
  54. //Get input?:0
  55. void input(char *buffer)
  56. {
  57. printf("Enter a String(max 100 Chars):");
  58. buffer = gets(buffer);
  59. }