Advertisement
fr1sk

Untitled

Jun 12th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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 <stdbool.h>
  9. #include <string.h>
  10. #define MSGLEN (16)
  11.  
  12. void checker(bool exp, const char *usrmsg, const char *file, const char *func, const int line){
  13. if(!(exp)){
  14. perror(usrmsg);
  15. fprintf(stderr, "%s %s %d\n", file, func, line);
  16. exit(EXIT_FAILURE);
  17. }
  18. }
  19. #define osAssert(exp, usrmsg) checker(exp, usrmsg, __FILE__, __func__, __LINE__);
  20.  
  21. int main(int argc, char **argv){
  22. osAssert(2 == argc, "nema dovoljno argumenara");
  23. int fd = open(argv[1], O_RDONLY);
  24. osAssert(-1 != fd, "open failed");
  25. int bytesRead;
  26. do{
  27. char buf[MSGLEN];
  28.  
  29. osAssert(-1 != (bytesRead = read(fd, buf, sizeof buf)), "read failed");
  30. if(0 == bytesRead){
  31. break;
  32. }
  33. printf("Read number: %d\n", atoi(buf));
  34. } while(true);
  35. close(fd);
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement