diff options
author | Martin Willi <martin@revosec.ch> | 2013-07-22 14:16:38 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2013-07-29 09:00:48 +0200 |
commit | 84044f9c7330e7eff485b82cfa9c93f9e17e5383 (patch) | |
tree | 003d21089fdff3f69a7d734728ebf08157359507 /src/libstrongswan/utils/utils.h | |
parent | 15483a622324b55da28ef4faa1cba6a899ea1039 (diff) | |
download | strongswan-84044f9c7330e7eff485b82cfa9c93f9e17e5383.tar.bz2 strongswan-84044f9c7330e7eff485b82cfa9c93f9e17e5383.tar.xz |
utils: add round_up/down() helper functions
Diffstat (limited to 'src/libstrongswan/utils/utils.h')
-rw-r--r-- | src/libstrongswan/utils/utils.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h index 0e103de9c..d055f712d 100644 --- a/src/libstrongswan/utils/utils.h +++ b/src/libstrongswan/utils/utils.h @@ -671,6 +671,29 @@ static inline u_int64_t untoh64(void *network) } /** + * 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 */ typedef u_int refcount_t; |