summaryrefslogtreecommitdiff
path: root/src/libstddjb/socket_internal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/socket_internal.c')
-rw-r--r--src/libstddjb/socket_internal.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libstddjb/socket_internal.c b/src/libstddjb/socket_internal.c
new file mode 100644
index 0000000..ae57e06
--- /dev/null
+++ b/src/libstddjb/socket_internal.c
@@ -0,0 +1,33 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+#include <skalibs/nonposix.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <skalibs/djbunix.h>
+
+#ifdef SKALIBS_HASACCEPT4
+
+int socket_internal (int domain, int type, int protocol, unsigned int flags)
+{
+ return socket(domain, type | ((flags & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((flags & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0), protocol) ;
+}
+
+#else
+
+int socket_internal (int domain, int type, int protocol, unsigned int flags)
+{
+ int s = socket(domain, type, protocol) ;
+ if (s == -1) return -1 ;
+ if ((((flags & DJBUNIX_FLAG_NB) ? ndelay_on(s) : ndelay_off(s)) < 0)
+ || (((flags & DJBUNIX_FLAG_COE) ? coe(s) : uncoe(s)) < 0))
+ {
+ register int e = errno ;
+ fd_close(s) ;
+ errno = e ;
+ return -1 ;
+ }
+ return s ;
+}
+
+#endif