aboutsummaryrefslogtreecommitdiffstats
path: root/test.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-17 16:33:49 +0100
committerMattias Andrée <maandree@kth.se>2022-01-17 16:33:49 +0100
commita3f58d46bc1a6500a939908c6654ec0fc4288622 (patch)
treed1d1c63d0f537ca724332bbfd847ac999e64e737 /test.c
parentFix config.mk: add -lblake (diff)
downloadlibar2-a3f58d46bc1a6500a939908c6654ec0fc4288622.tar.gz
libar2-a3f58d46bc1a6500a939908c6654ec0fc4288622.tar.bz2
libar2-a3f58d46bc1a6500a939908c6654ec0fc4288622.tar.xz
test: improve portability
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--test.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/test.c b/test.c
index 1e99961..9aea93a 100644
--- a/test.c
+++ b/test.c
@@ -16,13 +16,19 @@ static int from_lineno = 0;
static void *
allocate(size_t num, size_t size, size_t alignment, struct libar2_context *ctx)
{
+#ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 0
+#endif
+#if _POSIX_C_SOURCE >= 200112L
void *ptr;
int err;
+#endif
(void) ctx;
if (num > SIZE_MAX / size) {
errno = ENOMEM;
return NULL;
}
+#if _POSIX_C_SOURCE >= 200112L
if (alignment < sizeof(void *))
alignment = sizeof(void *);
err = posix_memalign(&ptr, alignment, num * size);
@@ -32,6 +38,12 @@ allocate(size_t num, size_t size, size_t alignment, struct libar2_context *ctx)
} else {
return ptr;
}
+#elif defined(_ISOC11_SOURCE)
+ return aligned_alloc(alignment, num * size);
+#else
+ (void) alignment;
+ return malloc(num * size);
+#endif
}
static void
@@ -660,7 +672,7 @@ check_hash(const char *pwd_, size_t pwdlen, const char *hash, struct libar2_cont
from_lineno = lineno;
errno = 0;
- stpcpy(pwd, pwd_);
+ strcpy(pwd, pwd_);
plen = libar2_decode_params(hash, &params, &sbuf, ctx);
assert(!libar2_validate_params(&params, NULL));
assert(!libar2_hash(output, pwd, pwdlen, &params, ctx));