utils: add round_up/down() helper functions

This commit is contained in:
Martin Willi
2013-07-29 09:00:48 +02:00
parent 15483a6223
commit 84044f9c73
2 changed files with 49 additions and 0 deletions
+23
View File
@@ -670,6 +670,29 @@ static inline u_int64_t untoh64(void *network)
#endif
}
/**
* Round up size to be multiple of alignement
*/
static inline size_t round_up(size_t size, int alignement)
{
int remainder;
remainder = size % alignement;
if (remainder)
{
size += alignement - remainder;
}
return size;
}
/**
* Round down size to be a multiple of alignement
*/
static inline size_t round_down(size_t size, int alignement)
{
return size - (size % alignement);
}
/**
* Special type to count references
*/