diff options
author | Mattias Andrée <maandree@kth.se> | 2022-01-17 16:33:49 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-01-17 16:33:49 +0100 |
commit | a3f58d46bc1a6500a939908c6654ec0fc4288622 (patch) | |
tree | d1d1c63d0f537ca724332bbfd847ac999e64e737 | |
parent | Fix config.mk: add -lblake (diff) | |
download | libar2-a3f58d46bc1a6500a939908c6654ec0fc4288622.tar.gz libar2-a3f58d46bc1a6500a939908c6654ec0fc4288622.tar.bz2 libar2-a3f58d46bc1a6500a939908c6654ec0fc4288622.tar.xz |
test: improve portability
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | test.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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, ¶ms, &sbuf, ctx); assert(!libar2_validate_params(¶ms, NULL)); assert(!libar2_hash(output, pwd, pwdlen, ¶ms, ctx)); |