tryaccept4.c (561B)
1 /* ISC license. */ 2 3 #undef _POSIX_C_SOURCE 4 #undef _XOPEN_SOURCE 5 6 #ifndef _XPG4_2 7 #define _XPG4_2 8 #endif 9 10 #ifndef _GNU_SOURCE 11 #define _GNU_SOURCE 12 #endif 13 14 #ifndef _DEFAULT_SOURCE 15 #define _DEFAULT_SOURCE 16 #endif 17 18 #include <sys/socket.h> 19 #include <sys/stat.h> 20 #include <fcntl.h> 21 #include <errno.h> 22 23 int main (void) 24 { 25 struct sockaddr blah ; 26 socklen_t blahlen = sizeof(blah) ; 27 int fd = open("/dev/null", O_RDONLY | O_NONBLOCK) ; 28 if (fd < 0) return 111 ; 29 if ((accept4(fd, &blah, &blahlen, SOCK_NONBLOCK) < 0) && (errno != ENOTSOCK)) return 1 ; 30 return 0 ; 31 }