Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. #define MSG_SIZE 80
  8. #define PIPENAME "./tmp/named_pipe_file"
  9.  
  10. int main(void) {
  11. char msg[MSG_SIZE];
  12. int fd;
  13. int nread, i;
  14.  
  15.  
  16. if ((fd = open(PIPENAME, O_WRONLY)) < 0) {
  17. printf("fail to open named pipe\n");
  18. return 0;
  19. }
  20.  
  21.  
  22. for (i = 0; i < 3; i++) {
  23.  
  24. fgets(msg, MSG_SIZE, stdin);
  25.  
  26. if ((nread = write(fd, msg, sizeof(msg))) < 0 ) {
  27. printf("fail to call write()\n");
  28. return 0;
  29. }
  30.  
  31. }
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement