From 4e1d9aef948092778ff0559ee8a94d4365dab9cf Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 29 Jan 2022 16:08:16 +0100 Subject: Fix: libfstream: don't fail on Windows when reading from a pipe When piping the output of another program into tar2sqfs.exe, and the source program terminates, tar2sqfs.exe gets an ERROR_BROKEN_PIPE when the end is reached and it trys to pre-cache more data. This commit adds a work around, to propperly handle this as and end-of-file condition. Signed-off-by: David Oberhollenzer --- lib/fstream/win32/istream.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/fstream/win32/istream.c b/lib/fstream/win32/istream.c index 36d7c42..b591584 100644 --- a/lib/fstream/win32/istream.c +++ b/lib/fstream/win32/istream.c @@ -30,6 +30,16 @@ static int file_precache(istream_t *strm) if (!ReadFile(hnd, strm->buffer + strm->buffer_used, diff, &actual, NULL)) { + DWORD error = GetLastError(); + + if (error == ERROR_HANDLE_EOF || + error == ERROR_BROKEN_PIPE) { + strm->eof = true; + break; + } + + SetLastError(error); + w32_perror(file->path == NULL ? "stdin" : file->path); return -1; } -- cgit v1.2.3