Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/amachronic/microtar.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-11-04 20:58:49 +0300
committerAidan MacDonald <amachronic@protonmail.com>2021-11-05 02:50:29 +0300
commit05672174a5533c84c60c3be9bc85ac8f9a4eb571 (patch)
treeacc4ff1777c52d031bd8aab77d9bd71bcc4883ea
parent572de1fe95fd71ae28499018529e1b31bacee02a (diff)
Specialize round_up -> round_up_512
We don't need to round up to arbitrary multiples; using constants should allow the compiler to optimize better.
-rw-r--r--src/microtar.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/microtar.c b/src/microtar.c
index 84d7eca..0b0e0e7 100644
--- a/src/microtar.c
+++ b/src/microtar.c
@@ -77,9 +77,9 @@ static int print_octal(char* str, size_t len, unsigned value)
return MTAR_ESUCCESS;
}
-static unsigned round_up(unsigned n, unsigned incr)
+static unsigned round_up_512(unsigned n)
{
- return n + (incr - n % incr) % incr;
+ return (n + 511u) & ~511u;
}
static int tread(mtar_t* tar, void* data, unsigned size)
@@ -273,7 +273,7 @@ int mtar_next(mtar_t* tar)
return err;
/* Seek to next record */
- n = round_up(tar->header.size, 512) + HEADER_LEN;
+ n = round_up_512(tar->header.size) + HEADER_LEN;
return mtar_seek(tar, tar->pos + n);
}
@@ -427,7 +427,7 @@ int mtar_write_data(mtar_t* tar, const void* data, unsigned size)
/* Write padding if we've written all the data for this file */
if(tar->remaining_data == 0)
- return write_null_bytes(tar, round_up(tar->pos, 512) - tar->pos);
+ return write_null_bytes(tar, round_up_512(tar->pos) - tar->pos);
return MTAR_ESUCCESS;
}