From 71f11e6cf63289d51f152469a0da81a85fe2608c Mon Sep 17 00:00:00 2001 From: Leonardo Hernández Hernández Date: Thu, 27 Jun 2024 13:19:16 -0600 Subject: set O_NONBLOCK flag to stdout --- 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