utils: add round_up/down() helper functions
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user