summaryrefslogtreecommitdiff
path: root/lib/common/io_stdin.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-06 11:54:56 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-06 11:56:02 +0100
commit4d46b361ff1371a6f3f4f89ed8ca81ee23e86de8 (patch)
tree0705d7c216ea345665cd38345bc21f8931195849 /lib/common/io_stdin.c
parent3afffc2a59cfc3888a84b2b2305b5312393ff4e8 (diff)
Remove raw file descriptors from tar read path
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/io_stdin.c')
-rw-r--r--lib/common/io_stdin.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/common/io_stdin.c b/lib/common/io_stdin.c
index 9e96e45..ea73771 100644
--- a/lib/common/io_stdin.c
+++ b/lib/common/io_stdin.c
@@ -46,7 +46,7 @@ static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset,
size_t temp_size = 0;
sqfs_u8 *temp = NULL;
sqfs_u64 diff;
- ssize_t ret;
+ size_t ret;
if (offset < file->offset)
return SQFS_ERROR_IO;
@@ -60,24 +60,21 @@ static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset,
return SQFS_ERROR_OUT_OF_BOUNDS;
while (size > 0) {
+ if (ferror(stdin))
+ return SQFS_ERROR_IO;
+
+ if (feof(stdin))
+ return SQFS_ERROR_OUT_OF_BOUNDS;
+
if (offset > file->offset) {
diff = file->offset - offset;
diff = diff > (sqfs_u64)temp_size ? temp_size : diff;
- ret = read(STDIN_FILENO, temp, diff);
+ ret = fread(temp, 1, diff, stdin);
} else {
- ret = read(STDIN_FILENO, buffer, size);
- }
-
- if (ret < 0) {
- if (errno == EINTR)
- continue;
- return SQFS_ERROR_IO;
+ ret = fread(buffer, 1, size, stdin);
}
- if (ret == 0)
- return SQFS_ERROR_OUT_OF_BOUNDS;
-
if (offset <= file->offset) {
buffer = (char *)buffer + ret;
size -= ret;