aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-16 22:38:30 +0100
committerMattias Andrée <maandree@kth.se>2022-02-16 22:38:30 +0100
commit7ed8efcac4ee646a232ee29c2dad87e6a6e35817 (patch)
tree9afa6c49759a33def375beab05a07a0efbe12c5f
parentFix check for 0-prefixed integers parameter string (diff)
downloadlibar2-7ed8efcac4ee646a232ee29c2dad87e6a6e35817.tar.gz
libar2-7ed8efcac4ee646a232ee29c2dad87e6a6e35817.tar.bz2
libar2-7ed8efcac4ee646a232ee29c2dad87e6a6e35817.tar.xz
Make test code work with musl1.1.1
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--test.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/test.c b/test.c
index 3a0ac41..4e9e8fb 100644
--- a/test.c
+++ b/test.c
@@ -37,6 +37,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
int err;
@@ -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