Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/uio.h>
- #include <unistd.h>
- #include <stdbool.h>
- #include <string.h>
- #define MSGLEN (16)
- void checker(bool exp, const char *usrmsg, const char *file, const char *func, const int line){
- if(!(exp)){
- perror(usrmsg);
- fprintf(stderr, "%s %s %d\n", file, func, line);
- exit(EXIT_FAILURE);
- }
- }
- #define osAssert(exp, usrmsg) checker(exp, usrmsg, __FILE__, __func__, __LINE__);
- int main(int argc, char **argv){
- osAssert(2 == argc, "nema dovoljno argumenara");
- int fd = open(argv[1], O_RDONLY);
- osAssert(-1 != fd, "open failed");
- int bytesRead;
- do{
- char buf[MSGLEN];
- osAssert(-1 != (bytesRead = read(fd, buf, sizeof buf)), "read failed");
- if(0 == bytesRead){
- break;
- }
- printf("Read number: %d\n", atoi(buf));
- } while(true);
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement