Provide a helper function to round a value up to the nearest page size for malloc optimisations.

This commit is contained in:
Con Kolivas 2013-09-14 11:41:57 +10:00
parent d5c00f96f7
commit 6bb837761f
2 changed files with 13 additions and 1 deletions

13
util.c
View file

@ -149,6 +149,15 @@ void round_to_page(i64 *size)
*size = PAGE_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) bool get_rand(rzip_control *control, uchar *buf, int len)
{ {
int fd, i; 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); fatal_return(("Failed to close fd in get_rand\n"), false);
} }
return true; return true;
}bool read_config(rzip_control *control) }
bool read_config(rzip_control *control)
{ {
/* check for lrzip.conf in ., $HOME/.lrzip and /etc/lrzip */ /* check for lrzip.conf in ., $HOME/.lrzip and /etc/lrzip */
char *HOME, homeconf[255]; char *HOME, homeconf[255];

1
util.h
View file

@ -82,6 +82,7 @@ static inline void failure(const rzip_control *control, unsigned int line, const
void setup_overhead(rzip_control *control); void setup_overhead(rzip_control *control);
void setup_ram(rzip_control *control); void setup_ram(rzip_control *control);
void round_to_page(i64 *size); 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 get_rand(rzip_control *control, uchar *buf, int len);
bool read_config(rzip_control *control); bool read_config(rzip_control *control);
void lrz_stretch(rzip_control *control); void lrz_stretch(rzip_control *control);