summaryrefslogtreecommitdiff
path: root/src/test/test-util.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-09-22 12:05:16 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-09-22 14:27:02 +0200
commit95d78c7e7c81a6b788f28c33ef2cafd87471a0d7 (patch)
tree165ff83c1a3c42ca003e15d1211062254dd830c8 /src/test/test-util.c
parenteee846339d2f76f568c62b3725bf75bcee728115 (diff)
util: add alloca_align()
The alloca_align() helper is the alloca() equivalent of posix_memalign(). As there is no such function provided by glibc, we simply account for additional memory and return a pointer offset into the allocated memory to grant the alignment. Furthermore, alloca0_align() is added, which simply clears the allocated memory.
Diffstat (limited to 'src/test/test-util.c')
-rw-r--r--src/test/test-util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index f8e42f3a55..1311184815 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -131,6 +131,19 @@ static void test_container_of(void) {
v1) == &myval);
}
+static void test_alloca(void) {
+ static const uint8_t zero[997] = { };
+ char *t;
+
+ t = alloca_align(17, 512);
+ assert_se(!((uintptr_t)t & 0xff));
+ memzero(t, 17);
+
+ t = alloca0_align(997, 1024);
+ assert_se(!((uintptr_t)t & 0x1ff));
+ assert_se(!memcmp(t, zero, 997));
+}
+
static void test_first_word(void) {
assert_se(first_word("Hello", ""));
assert_se(first_word("Hello", "Hello"));
@@ -1272,6 +1285,7 @@ int main(int argc, char *argv[]) {
test_align_power2();
test_max();
test_container_of();
+ test_alloca();
test_first_word();
test_close_many();
test_parse_boolean();