diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-08-12 11:05:09 +0300 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-08-12 11:05:09 +0300 |
commit | dee6ffa492c2efee982dcd0b4724213317eceb37 (patch) | |
tree | add143a84e1679384f0101e86cc712d387387a89 /src/gunzip.c | |
parent | bd9835a20ee6b191c844ebba0433e5d321c976f4 (diff) | |
download | apk-tools-dee6ffa492c2efee982dcd0b4724213317eceb37.tar.gz apk-tools-dee6ffa492c2efee982dcd0b4724213317eceb37.tar.bz2 apk-tools-dee6ffa492c2efee982dcd0b4724213317eceb37.tar.xz apk-tools-dee6ffa492c2efee982dcd0b4724213317eceb37.zip |
io: better error handling when writing stuff out
also have the output stream support writing to temporary file
and do renameat/unlinkat on close depending on if all writes
succeeded or not.
Diffstat (limited to 'src/gunzip.c')
-rw-r--r-- | src/gunzip.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/gunzip.c b/src/gunzip.c index e5144a0..dd8d248 100644 --- a/src/gunzip.c +++ b/src/gunzip.c @@ -190,24 +190,29 @@ static ssize_t gzo_write(void *stream, const void *ptr, size_t size) return size; } -static void gzo_close(void *stream) +static int gzo_close(void *stream) { struct apk_gzip_ostream *gos = (struct apk_gzip_ostream *) stream; unsigned char buffer[1024]; size_t have; - int r; + int r, rc = 0; do { gos->zs.avail_out = sizeof(buffer); gos->zs.next_out = buffer; r = deflate(&gos->zs, Z_FINISH); have = sizeof(buffer) - gos->zs.avail_out; - gos->output->write(gos->output, buffer, have); + if (gos->output->write(gos->output, buffer, have) != have) + rc = -EIO; } while (r == Z_OK); - gos->output->close(gos->output); + r = gos->output->close(gos->output); + if (r != 0) + rc = r; deflateEnd(&gos->zs); free(stream); + + return rc; } struct apk_ostream *apk_ostream_gzip(struct apk_ostream *output) |