chiark / gitweb /
cprogs: Move nonblock() to common.[co]
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Aug 2022 19:02:57 +0000 (20:02 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 20:21:10 +0000 (21:21 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cprogs/common.c
cprogs/common.h
cprogs/mcastsoundd.c

index b0542926a29085f660a7b653f3a1883452122281..e8efed6639801ea538a73551b89962bed6b52618 100644 (file)
@@ -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");
+}
index 67eb4f6b0a5089244528408e61467a56cdcc719e..94a1a5eb1492d3c9bf4ecb61f6735374604928d3 100644 (file)
@@ -32,6 +32,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <fcntl.h>
 
 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);
 
index 8a8c67010de2c7bffb37f24e5a025e094d30210a..ead525fba84009fe1e99adee7dd9ec9c3ea8d121 100644 (file)
 
 #include <endian.h>
 #include <sys/types.h>
-#include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
 #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;