aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/utils.h
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-10-12 01:01:06 +0200
committerTobias Brunner <tobias@strongswan.org>2013-10-17 10:25:34 +0200
commit812ae898bfa4917e2d69b17b0c3949bb2c2c2b18 (patch)
treef50f6ec9c8aba0490257d77401578815ff873c58 /src/libstrongswan/utils/utils.h
parent32fef0c6e9e934eef2e63286eef13ff491df5aaf (diff)
downloadstrongswan-812ae898bfa4917e2d69b17b0c3949bb2c2c2b18.tar.bz2
strongswan-812ae898bfa4917e2d69b17b0c3949bb2c2c2b18.tar.xz
utils: Add utility function to calculate padding length
Diffstat (limited to 'src/libstrongswan/utils/utils.h')
-rw-r--r--src/libstrongswan/utils/utils.h28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h
index 8fe741211..5c237a7f2 100644
--- a/src/libstrongswan/utils/utils.h
+++ b/src/libstrongswan/utils/utils.h
@@ -679,26 +679,30 @@ static inline u_int64_t untoh64(void *network)
}
/**
- * Round up size to be multiple of alignement
+ * Get the padding required to make size a multiple of alignment
*/
-static inline size_t round_up(size_t size, int alignement)
+static inline size_t pad_len(size_t size, size_t alignment)
{
- int remainder;
+ size_t remainder;
- remainder = size % alignement;
- if (remainder)
- {
- size += alignement - remainder;
- }
- return size;
+ remainder = size % alignment;
+ return remainder ? alignment - remainder : 0;
+}
+
+/**
+ * Round up size to be multiple of alignment
+ */
+static inline size_t round_up(size_t size, size_t alignment)
+{
+ return size + pad_len(size, alignment);
}
/**
- * Round down size to be a multiple of alignement
+ * Round down size to be a multiple of alignment
*/
-static inline size_t round_down(size_t size, int alignement)
+static inline size_t round_down(size_t size, size_t alignment)
{
- return size - (size % alignement);
+ return size - (size % alignment);
}
/**