aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..b4053fd
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include "util.h"
+#include "constant.h"
+
+void panic(const char *msg)
+{
+ perror(msg);
+ exit(EXIT_FAILURE);
+}
+
+int setblocking(int fd, bool blocking)
+{
+ u_long mode = blocking ? 0 : 1;
+ if (ioctl(fd, FIONBIO, &mode) == -1)
+ return ERROR;
+
+ return OK;
+}