From a936783e1728c28d9cb690a750792d0e08c6a422 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Wed, 12 Jun 2013 14:37:36 +0200 Subject: ioops: mark failure path as unlikely Just tell GCC that those paths are unexpected. Signed-off-by: Daniel Borkmann --- ioops.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ioops.c b/ioops.c index 4ac0f3a..07cce9c 100644 --- a/ioops.c +++ b/ioops.c @@ -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)); -- cgit v1.2.3-54-g00ecf