From dde1d66ddc3236d076858736fb6faaf06a3c7d8c Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sun, 7 Jul 2024 18:42:35 +0530 Subject: updstream --- util.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index cca7c19..51130af 100644 --- a/util.c +++ b/util.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "util.h" @@ -33,3 +34,18 @@ ecalloc(size_t nmemb, size_t size) die("calloc:"); return p; } + +int +fd_set_nonblock(int fd) { + int flags = fcntl(fd, F_GETFL); + if (flags < 0) { + perror("fcntl(F_GETFL):"); + return -1; + } + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) { + perror("fcntl(F_SETFL):"); + return -1; + } + + return 0; +} -- cgit v1.2.3