From: Paul Eggert Date: Mon, 25 Feb 2013 19:24:14 +0000 (-0800) Subject: gzip: port to DMF file systems X-Git-Tag: v1.6~11 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=6ea2e1bf864059de97981ab34e7f2331b5aad218;p=debian%2Fgzip gzip: port to DMF file systems * util.c (read_buffer): When reading a file with O_NONBLOCK, if the read fails with errno==EAGAIN, clear O_NONBLOCK and try again. Problem reported by Vitezslav Cizek in . --- diff --git a/util.c b/util.c index cfd4e6c..c4c7f70 100644 --- a/util.c +++ b/util.c @@ -132,16 +132,35 @@ int fill_inbuf(eof_ok) } /* Like the standard read function, except do not attempt to read more - than SSIZE_MAX bytes at a time. */ + than INT_MAX bytes at a time. */ int read_buffer (fd, buf, cnt) int fd; voidp buf; unsigned int cnt; { + int len; if (INT_MAX < cnt) cnt = INT_MAX; - return read (fd, buf, cnt); + 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; } /* Likewise for 'write'. */