summaryrefslogtreecommitdiff
path: root/ioops.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-06-12 14:33:43 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-06-12 14:33:43 +0200
commitdfb45a7ac75d17c3a8421bfb53840d6db271a121 (patch)
tree3d9882f7c077d7ff431a1379f89f2115640ce201 /ioops.c
parent44b463529a8a9f2ccd1ec2acb8a4dfc117a636cb (diff)
ioops: misc: add dup{,2}_or_die to ioops
Bail out if it should ever fail. Detected by coverty in the translate_pcap_to_txf() path. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'ioops.c')
-rw-r--r--ioops.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ioops.c b/ioops.c
index 7cec2fd..4ac0f3a 100644
--- a/ioops.c
+++ b/ioops.c
@@ -12,6 +12,7 @@
#include "dev.h"
#include "ioops.h"
#include "str.h"
+#include "built_in.h"
int open_or_die(const char *file, int flags)
{
@@ -30,6 +31,21 @@ int open_or_die_m(const char *file, int flags, mode_t mode)
return ret;
}
+int dup_or_die(int oldfd)
+{
+ int newfd = dup(oldfd);
+ if (unlikely(newfd < 0))
+ panic("Cannot dup old file descriptor!\n");
+ return newfd;
+}
+
+void dup2_or_die(int oldfd, int newfd)
+{
+ int ret = dup2(oldfd, newfd);
+ if (unlikely(ret < 0))
+ panic("Cannot dup2 old/new file descriptor!\n");
+}
+
void create_or_die(const char *file, mode_t mode)
{
int fd = open_or_die_m(file, O_WRONLY | O_CREAT, mode);