nkiss

WIP
git clone git://git.nihaljere.xyz/nkiss
Log | Files | Refs

commit bd71f08d1c73d2acc47e9cdcf37b7a017a781200
parent df4d51f5e13917345f764fd5ed7f7dae9d43f5ed
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Wed, 24 Feb 2021 17:52:11 -0600

tar.c: remove redundant if

Diffstat:
Mtar.c | 53+++++++++++++++++++++++------------------------------
1 file changed, 23 insertions(+), 30 deletions(-)

diff --git a/tar.c b/tar.c @@ -777,42 +777,35 @@ int extract_entry(const gzFile gzf, struct tar_t *entry, const char verbosity) { } free(path); - if ((entry->type == REGULAR) || (entry->type == NORMAL) || (entry->type == CONTIGUOUS)) { - // create file - const unsigned int size = oct2uint(entry->size, 11); - int f = open(entry->name, O_WRONLY | O_CREAT | O_TRUNC, oct2uint(entry->mode, 7) & 0777); - if (f < 0) { - RC_ERROR("Unable to open file %s: %s", entry->name, strerror(rc)); - } - - // move archive pointer to data location - if (gzseek(gzf, 512 + entry->begin, SEEK_SET) == (off_t) (-1)) { - RC_ERROR("Bad index: %s", strerror(rc)); - } - - // copy data to file - char buf[512]; - int got = 0; - while (got < size) { - int r; - if ((r = gzread_size(gzf, buf, MIN(size - got, 512))) < 0) { - EXIST_ERROR("Unable to read from archive: %s", strerror(rc)); - } + // create file + const unsigned int size = oct2uint(entry->size, 11); + int f = open(entry->name, O_WRONLY | O_CREAT | O_TRUNC, oct2uint(entry->mode, 7) & 0777); + if (f < 0) { + RC_ERROR("Unable to open file %s: %s", entry->name, strerror(rc)); + } - if (write(f, buf, r) != r) { - EXIST_ERROR("Unable to write to %s: %s", entry->name, strerror(rc)); - } + // move archive pointer to data location + if (gzseek(gzf, 512 + entry->begin, SEEK_SET) == (off_t) (-1)) { + RC_ERROR("Bad index: %s", strerror(rc)); + } - got += r; + // copy data to file + char buf[512]; + int got = 0; + while (got < size) { + int r; + if ((r = gzread_size(gzf, buf, MIN(size - got, 512))) < 0) { + EXIST_ERROR("Unable to read from archive: %s", strerror(rc)); } - close(f); - } - else if ((entry->type == CHAR) || (entry->type == BLOCK)) { - if (mknod(entry->name, oct2uint(entry->mode, 7), (oct2uint(entry->major, 7) << 20) | oct2uint(entry->minor, 7)) < 0) { - EXIST_ERROR("Unable to make device %s: %s", entry->name, strerror(rc)); + if (write(f, buf, r) != r) { + EXIST_ERROR("Unable to write to %s: %s", entry->name, strerror(rc)); } + + got += r; } + + close(f); } else if (entry->type == HARDLINK) { if (link(entry->link_name, entry->name) < 0) {