mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-09-15 07:18:29 -04:00
gzip, gunzip: avoid hanging when opening special files
This matches the behavior of GNU gzip.
This commit is contained in:
parent
f100a42c02
commit
3a7658d144
@ -42,11 +42,17 @@
|
|||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
# define O_BINARY 0
|
# define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef O_SEQUENTIAL
|
||||||
|
# define O_SEQUENTIAL 0
|
||||||
|
#endif
|
||||||
#ifndef O_NOFOLLOW
|
#ifndef O_NOFOLLOW
|
||||||
# define O_NOFOLLOW 0
|
# define O_NOFOLLOW 0
|
||||||
#endif
|
#endif
|
||||||
#ifndef O_SEQUENTIAL
|
#ifndef O_NONBLOCK
|
||||||
# define O_SEQUENTIAL 0
|
# define O_NONBLOCK 0
|
||||||
|
#endif
|
||||||
|
#ifndef O_NOCTTY
|
||||||
|
# define O_NOCTTY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The invocation name of the program (filename component only) */
|
/* The invocation name of the program (filename component only) */
|
||||||
@ -216,7 +222,7 @@ xopen_for_read(const tchar *path, bool symlink_ok, struct file_stream *strm)
|
|||||||
if (strm->name == NULL)
|
if (strm->name == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strm->fd = topen(path, O_RDONLY | O_BINARY |
|
strm->fd = topen(path, O_RDONLY | O_BINARY | O_NONBLOCK | O_NOCTTY |
|
||||||
(symlink_ok ? 0 : O_NOFOLLOW) | O_SEQUENTIAL);
|
(symlink_ok ? 0 : O_NOFOLLOW) | O_SEQUENTIAL);
|
||||||
if (strm->fd < 0) {
|
if (strm->fd < 0) {
|
||||||
msg_errno("Can't open %"TS" for reading", strm->name);
|
msg_errno("Can't open %"TS" for reading", strm->name);
|
||||||
@ -361,6 +367,8 @@ xread(struct file_stream *strm, void *buf, size_t count)
|
|||||||
if (res == 0)
|
if (res == 0)
|
||||||
break;
|
break;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
|
continue;
|
||||||
msg_errno("Error reading from %"TS, strm->name);
|
msg_errno("Error reading from %"TS, strm->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user