+ len = read (fd, buf, cnt);
+
+#if defined F_SETFL && O_NONBLOCK && defined EAGAIN
+ /* Input files are opened O_NONBLOCK for security reasons. On some
+ file systems this can cause read to fail with errno == EAGAIN. */
+ if (len < 0 && errno == EAGAIN)
+ {
+ int flags = fcntl (fd, F_GETFL);
+ if (0 <= flags)
+ {
+ if (! (flags & O_NONBLOCK))
+ errno = EAGAIN;
+ else if (fcntl (fd, F_SETFL, flags & ~O_NONBLOCK) != -1)
+ len = read (fd, buf, cnt);
+ }
+ }
+#endif
+
+ return len;