From 6bb837761f5883a9763e4eb167c1140c1304632f Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 14 Sep 2013 11:41:57 +1000 Subject: [PATCH] Provide a helper function to round a value up to the nearest page size for malloc optimisations. --- util.c | 13 ++++++++++++- util.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index b45eb6e..8190364 100644 --- a/util.c +++ b/util.c @@ -149,6 +149,15 @@ void round_to_page(i64 *size) *size = PAGE_SIZE; } +size_t round_up_page(rzip_control *control, size_t len) +{ + int rem = len % control->page_size; + + if (rem) + len += control->page_size - rem; + return len; +} + bool get_rand(rzip_control *control, uchar *buf, int len) { int fd, i; @@ -164,7 +173,9 @@ bool get_rand(rzip_control *control, uchar *buf, int len) fatal_return(("Failed to close fd in get_rand\n"), false); } return true; -}bool read_config(rzip_control *control) +} + +bool read_config(rzip_control *control) { /* check for lrzip.conf in ., $HOME/.lrzip and /etc/lrzip */ char *HOME, homeconf[255]; diff --git a/util.h b/util.h index 667262b..3ba8064 100644 --- a/util.h +++ b/util.h @@ -82,6 +82,7 @@ static inline void failure(const rzip_control *control, unsigned int line, const void setup_overhead(rzip_control *control); void setup_ram(rzip_control *control); void round_to_page(i64 *size); +size_t round_up_page(rzip_control *control, size_t len); bool get_rand(rzip_control *control, uchar *buf, int len); bool read_config(rzip_control *control); void lrz_stretch(rzip_control *control);