diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-06 10:44:26 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-06 11:10:58 +0100 |
commit | 3afffc2a59cfc3888a84b2b2305b5312393ff4e8 (patch) | |
tree | 029ac4c5f55e9e7149cd40d0f57c52efcd41608f /lib/tar/write_retry.c | |
parent | 9f1f3f959d3411c200afb5a1df4fffa9d87df616 (diff) |
Remove raw file descriptors from unpack write paths
Instead, use stdio FILE pointers. On POSIX systems, use fileno to get
the file descriptor and hopefully create sparase files.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/write_retry.c')
-rw-r--r-- | lib/tar/write_retry.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/tar/write_retry.c b/lib/tar/write_retry.c index 1ff1a7e..3977db1 100644 --- a/lib/tar/write_retry.c +++ b/lib/tar/write_retry.c @@ -12,23 +12,22 @@ #include "tar.h" -int write_retry(const char *errstr, int fd, const void *data, size_t size) +int write_retry(const char *errstr, FILE *fp, const void *data, size_t size) { - ssize_t ret; + size_t ret; while (size > 0) { - ret = write(fd, data, size); - if (ret == 0) { + if (feof(fp)) { fprintf(stderr, "%s: write truncated\n", errstr); return -1; } - if (ret < 0) { - if (errno == EINTR) - continue; - perror(errstr); + + if (ferror(fp)) { + fprintf(stderr, "%s: error writing to file\n", errstr); return -1; } + ret = fwrite(data, 1, size, fp); data = (const char *)data + ret; size -= ret; } |