diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-06-21 12:55:32 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-06-21 12:55:32 +0300 |
commit | 22281fb4b583a5969a9c902c008e336e7cc421ff (patch) | |
tree | 469b88a8e053c669934524caff018c4c8d86e09a /src/io.c | |
parent | ca784ceab3f504b7cf9f481ccb76dee021abd76c (diff) | |
download | apk-tools-22281fb4b583a5969a9c902c008e336e7cc421ff.tar.gz apk-tools-22281fb4b583a5969a9c902c008e336e7cc421ff.tar.bz2 apk-tools-22281fb4b583a5969a9c902c008e336e7cc421ff.tar.xz apk-tools-22281fb4b583a5969a9c902c008e336e7cc421ff.zip |
print: handle write() errors in apk_print_progress()
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -33,6 +33,22 @@ size_t apk_io_bufsize = 128*1024; +ssize_t apk_write_fully(int fd, const void *ptr, size_t size) +{ + ssize_t i = 0, r; + + while (i < size) { + r = write(fd, ptr + i, size - i); + if (r <= 0) { + if (r == 0) return i; + return -errno; + } + i += r; + } + + return i; +} + static void apk_file_meta_from_fd(int fd, struct apk_file_meta *meta) { struct stat st; @@ -828,22 +844,6 @@ struct apk_fd_ostream { char buffer[1024]; }; -static ssize_t safe_write(int fd, const void *ptr, size_t size) -{ - ssize_t i = 0, r; - - while (i < size) { - r = write(fd, ptr + i, size - i); - if (r < 0) - return -errno; - if (r == 0) - return i; - i += r; - } - - return i; -} - static ssize_t fdo_flush(struct apk_fd_ostream *fos) { ssize_t r; @@ -851,7 +851,7 @@ static ssize_t fdo_flush(struct apk_fd_ostream *fos) if (fos->bytes == 0) return 0; - if ((r = safe_write(fos->fd, fos->buffer, fos->bytes)) != fos->bytes) { + if ((r = apk_write_fully(fos->fd, fos->buffer, fos->bytes)) != fos->bytes) { apk_ostream_cancel(&fos->os, r < 0 ? r : -EIO); return r; } @@ -870,7 +870,7 @@ static ssize_t fdo_write(struct apk_ostream *os, const void *ptr, size_t size) if (r != 0) return r; if (size >= sizeof(fos->buffer) / 2) { - r = safe_write(fos->fd, ptr, size); + r = apk_write_fully(fos->fd, ptr, size); if (r != size) apk_ostream_cancel(&fos->os, r < 0 ? r : -EIO); return r; } |