Blame SOURCES/gzip-1.5-nonblock.patch

81367e
diff --git a/util.c b/util.c
81367e
index 46bc89d..34fd789 100644
81367e
--- a/util.c
81367e
+++ b/util.c
81367e
@@ -139,9 +139,29 @@ read_buffer (fd, buf, cnt)
81367e
      voidp buf;
81367e
      unsigned int cnt;
81367e
 {
81367e
+  int len;
81367e
+#ifdef INT_MAX
81367e
   if (INT_MAX < cnt)
81367e
     cnt = INT_MAX;
81367e
-  return read (fd, buf, cnt);
81367e
+#endif
81367e
+  len = read (fd, buf, cnt);
81367e
+
81367e
+#if defined F_SETFL && O_NONBLOCK && defined EAGAIN
81367e
+  /* Iput files are opened O_NONBLOCK for security reasons. On some
81367e
+     file systems this can cause read to fail with errno == EAGAIN.  */
81367e
+  if (len < 0 && errno == EAGAIN)
81367e
+    {
81367e
+      int flags = fcntl (fd, F_GETFL);
81367e
+      if (0 <= flags)
81367e
+        {
81367e
+          if (! (flags & O_NONBLOCK))
81367e
+            errno = EAGAIN;
81367e
+          else if (fcntl (fd, F_SETFL, flags & ~O_NONBLOCK) != -1)
81367e
+            len = read (fd, buf, cnt);
81367e
+        }
81367e
+    }
81367e
+#endif
81367e
+  return len;
81367e
 }
81367e
 
81367e
 /* Likewise for 'write'.  */