Advertisement
fr1sk

Untitled

Jun 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6. #include <sys/uio.h>
  7. #include <unistd.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <sys/stat.h>
  11. #include <time.h>
  12. #include <string.h>
  13. #include <stdbool.h>
  14. #define MSGLEN (16)
  15.  
  16. void checker(bool exp, const char *usrmsg, const char *file, const char *func, const int line){
  17. if(!(exp)){
  18. perror(usrmsg);
  19. fprintf(stderr, "%s %s %d\n", file, func, line);
  20. exit(EXIT_FAILURE);
  21. }
  22. }
  23. #define osAssert(exp, usrmsg) checker(exp, usrmsg, __FILE__, __func__, __LINE__);
  24.  
  25. int main(int argc, char **argv){
  26. osAssert(2 == argc, "nema dovoljno argumenara");
  27. mode_t oldMask = umask(0);
  28. osAssert(-1 != mkfifo(argv[1], 0600), "make fifo failed");
  29. int fd = open(argv[1], O_WRONLY);
  30. osAssert(-1 != fd, "open failed");
  31. srand(time(NULL));
  32. char buf[MSGLEN];
  33. do{
  34. sprintf(buf, "%d", rand());
  35. osAssert(-1 != write(fd, buf, MSGLEN), "error write");
  36. printf("hocete jos? ");
  37. scanf("%s", buf);
  38. } while (!strcasecmp("da",buf));
  39. umask(oldMask);
  40. close(fd);
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement