From 3d9d2b0a729f31deb69ea0a4f9195279d3b62121 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 19 Aug 2022 20:02:57 +0100 Subject: [PATCH] cprogs: Move nonblock() to common.[co] Signed-off-by: Ian Jackson --- cprogs/common.c | 7 +++++++ cprogs/common.h | 2 ++ cprogs/mcastsoundd.c | 9 +-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cprogs/common.c b/cprogs/common.c index b054292..e8efed6 100644 --- a/cprogs/common.c +++ b/cprogs/common.c @@ -41,3 +41,10 @@ void *xmalloc(size_t sz) { if (!r) common_diee("malloc"); return r; } + +void nonblock(int fd) { + int r; + r= fcntl(fd,F_GETFL); if (r<0) common_diee("nonblock fcntl F_GETFL"); + r |= O_NONBLOCK; + r= fcntl(fd,F_SETFL,r); if (r<0) common_diee("nonblock fcntl F_GETFL"); +} diff --git a/cprogs/common.h b/cprogs/common.h index 67eb4f6..94a1a5e 100644 --- a/cprogs/common.h +++ b/cprogs/common.h @@ -32,6 +32,7 @@ #include #include #include +#include char *m_vasprintf(const char *fmt, va_list al); char *m_asprintf(const char *fmt, ...); @@ -39,6 +40,7 @@ char *m_asprintf(const char *fmt, ...); /* to be provided by program: */ void common_die(const char *what); void common_diee(const char *what); /* prints errno */ +void nonblock(int fd); void *xmalloc(size_t sz); diff --git a/cprogs/mcastsoundd.c b/cprogs/mcastsoundd.c index 8a8c670..ead525f 100644 --- a/cprogs/mcastsoundd.c +++ b/cprogs/mcastsoundd.c @@ -11,12 +11,12 @@ #include #include -#include #include #include #include #include "myopt.h" +#include "common.h" typedef unsigned char Byte; @@ -152,13 +152,6 @@ MARS /*---------- general stuff ----------*/ -static void nonblock(int fd) { - int r; - r= fcntl(fd,F_GETFL); if (r<0) sysfail("nonblock fcntl F_GETFL"); - r |= O_NONBLOCK; - r= fcntl(fd,F_SETFL,r); if (r<0) sysfail("nonblock fcntl F_GETFL"); -} - static void blocksignals(int how) { sigset_t set; int r; -- 2.30.2