aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-01-29 16:08:16 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-01-29 16:08:16 +0100
commit4e1d9aef948092778ff0559ee8a94d4365dab9cf (patch)
tree2a263ced03c2cbe44e96bedc47c8782f4fa2879b /lib
parent8e1a2644968ce048feecd7f480ed4cce7dec7f6b (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/fstream/win32/istream.c10
1 files changed, 10 insertions, 0 deletions
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;
}