skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

socket_internal.c (771B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/sysdeps.h>
      4 #include <skalibs/nonposix.h>
      5 
      6 #include <sys/socket.h>
      7 
      8 #include <skalibs/fcntl.h>
      9 #include <skalibs/djbunix.h>
     10 #include <skalibs/socket.h>
     11 
     12 #ifdef SKALIBS_HASACCEPT4
     13 
     14 int socket_internal (int domain, int type, int protocol, unsigned int flags)
     15 {
     16   return socket(domain, type | ((flags & O_NONBLOCK) ? SOCK_NONBLOCK : 0) | ((flags & O_CLOEXEC) ? SOCK_CLOEXEC : 0), protocol) ;
     17 }
     18 
     19 #else
     20 
     21 int socket_internal (int domain, int type, int protocol, unsigned int flags)
     22 {
     23   int s = socket(domain, type, protocol) ;
     24   if (s == -1) return -1 ;
     25   if ((((flags & O_NONBLOCK) ? ndelay_on(s) : ndelay_off(s)) < 0)
     26    || (((flags & O_CLOEXEC) ? coe(s) : uncoe(s)) < 0))
     27   {
     28     fd_close(s) ;
     29     return -1 ;
     30   }
     31   return s ;
     32 }
     33 
     34 #endif