openat: detect Solaris fchownat bug
[pspp] / lib / accept4.c
index 1203d9aff901c0297c077a09f3c3528a062a7a6f..fbcb609b8d96a659cb9d6068d79ce2e8e4b2ec96 100644 (file)
@@ -33,6 +33,26 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
 {
   int fd;
 
+#if HAVE_ACCEPT4
+# undef accept4
+  /* Try the system call first, if it exists.  (We may be running with a glibc
+     that has the function but with an older kernel that lacks it.)  */
+  {
+    /* Cache the information whether the system call really exists.  */
+    static int have_accept4_really; /* 0 = unknown, 1 = yes, -1 = no */
+    if (have_accept4_really >= 0)
+      {
+       int result = accept4 (sockfd, addr, addrlen, flags);
+       if (!(result < 0 && errno == ENOSYS))
+         {
+           have_accept4_really = 1;
+           return result;
+         }
+       have_accept4_really = -1;
+      }
+  }
+#endif
+
   /* Check the supported flags.  */
   if ((flags & ~(SOCK_CLOEXEC | O_TEXT | O_BINARY)) != 0)
     {