X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=util.c;h=c4c7f70532d6b14ff492dcecec25f542f500003f;hb=0f3fd696606ddc69dde22f5171903fd59989a735;hp=46bc89d687edaa8e30f503184811e60459d98866;hpb=4ee107046a0ffd91f6c60c787326a5e27b799f6d;p=debian%2Fgzip diff --git a/util.c b/util.c index 46bc89d..c4c7f70 100644 --- a/util.c +++ b/util.c @@ -1,6 +1,6 @@ /* util.c -- utility functions for gzip support - Copyright (C) 1997-1999, 2001-2002, 2006, 2009-2012 Free Software + Copyright (C) 1997-1999, 2001-2002, 2006, 2009-2013 Free Software Foundation, Inc. Copyright (C) 1992-1993 Jean-loup Gailly @@ -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'. */