From 7ed8efcac4ee646a232ee29c2dad87e6a6e35817 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 16 Feb 2022 22:38:30 +0100 Subject: Make test code work with musl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- test.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'test.c') diff --git a/test.c b/test.c index 3a0ac41..4e9e8fb 100644 --- a/test.c +++ b/test.c @@ -36,6 +36,13 @@ allocate(size_t num, size_t size, size_t alignment, struct libar2_context *ctx) { #ifndef _POSIX_C_SOURCE # define _POSIX_C_SOURCE 0 +#endif +#ifndef _ISOC11_SOURCE +# ifdef __STDC_VERSION__ +# if __STDC_VERSION__ >= 201112L +# define _ISOC11_SOURCE +# endif +# endif #endif void *ptr; #if _POSIX_C_SOURCE >= 200112L @@ -51,30 +58,27 @@ allocate(size_t num, size_t size, size_t alignment, struct libar2_context *ctx) } } if (num > SIZE_MAX / size) { - errno = ENOMEM; /* $covered$ */ - goto enomem; /* $covered$ */ + /* $covered{$ */ + errno = ENOMEM; + fail: /* $covered$ */ + fprintf(stderr, "Internal test failure: %s\n", strerror(errno)); + exit(2); + /* $covered}$ */ } #if _POSIX_C_SOURCE >= 200112L if (alignment < sizeof(void *)) alignment = sizeof(void *); err = posix_memalign(&ptr, alignment, num * size); - if (err) { - enomem: /* $covered$ */ - fprintf(stderr, "Internal test failure: %s\n", strerror(errno)); /* $covered$ */ - exit(2); /* $covered$ */ - } else { - return ptr; - } + if (err) + goto fail; #elif defined(_ISOC11_SOURCE) ptr = aligned_alloc(alignment, num * size); - if (!ptr) { - fprintf(stderr, "Internal test failure: %s\n", strerror(errno)); /* $covered$ */ - exit(2); /* $covered$ */ - } - return ptr; + if (!ptr) + goto fail; #else # error No implementation for aligned memory allocation available #endif + return ptr; } static void -- cgit v1.2.3-70-g09d2