diff options
-rw-r--r-- | ioops.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -17,16 +17,15 @@ int open_or_die(const char *file, int flags) { int ret = open(file, flags); - if (ret < 0) + if (unlikely(ret < 0)) panic("Cannot open file %s! %s.\n", file, strerror(errno)); - return ret; } int open_or_die_m(const char *file, int flags, mode_t mode) { int ret = open(file, flags, mode); - if (ret < 0) + if (unlikely(ret < 0)) panic("Cannot open or create file %s! %s.", file, strerror(errno)); return ret; } @@ -55,7 +54,7 @@ void create_or_die(const char *file, mode_t mode) void pipe_or_die(int pipefd[2], int flags) { int ret = pipe2(pipefd, flags); - if (ret < 0) + if (unlikely(ret < 0)) panic("Cannot create pipe2 event fd! %s.\n", strerror(errno)); } @@ -65,7 +64,7 @@ int tun_open_or_die(char *name, int type) short flags; struct ifreq ifr; - if (!name) + if (unlikely(!name)) panic("No name provided for tundev!\n"); fd = open_or_die("/dev/net/tun", O_RDWR); @@ -75,11 +74,11 @@ int tun_open_or_die(char *name, int type) strlcpy(ifr.ifr_name, name, IFNAMSIZ); ret = ioctl(fd, TUNSETIFF, &ifr); - if (ret < 0) + if (unlikely(ret < 0)) panic("ioctl screwed up! %s.\n", strerror(errno)); ret = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); - if (ret < 0) + if (unlikely(ret < 0)) panic("fctnl screwed up! %s.\n", strerror(errno)); flags = device_get_flags(name); @@ -92,7 +91,7 @@ int tun_open_or_die(char *name, int type) ssize_t read_or_die(int fd, void *buf, size_t len) { ssize_t ret = read(fd, buf, len); - if (ret < 0) { + if (unlikely(ret < 0)) { if (errno == EPIPE) die(); panic("Cannot read from descriptor! %s.\n", strerror(errno)); @@ -104,7 +103,7 @@ ssize_t read_or_die(int fd, void *buf, size_t len) ssize_t write_or_die(int fd, const void *buf, size_t len) { ssize_t ret = write(fd, buf, len); - if (ret < 0) { + if (unlikely(ret < 0)) { if (errno == EPIPE) die(); panic("Cannot write to descriptor! %s.", strerror(errno)); |