This standard function is not available everywhere, so we detect it and
provide a fallback if missing.
AC_TYPE_UINT8_T
# Checks for library functions.
-AC_CHECK_FUNCS([mkdir strcasecmp strdup strtol])
+AC_CHECK_FUNCS([mkdir strcasecmp strdup strndup strtol])
# Checks for libraries.
AC_SEARCH_LIBS([iconv_open], [iconv], AC_DEFINE(CONFIG_ICONV, 1, [use iconv]))
#endif // ASM
+#ifndef HAVE_STRNDUP
+char *ass_strndup(const char *s, size_t n)
+{
+ char *end = memchr(s, 0, n);
+ size_t len = end ? end - s : n;
+ char *new = len < SIZE_MAX ? malloc(len + 1) : NULL;
+ if (new) {
+ memcpy(new, s, len);
+ new[len] = 0;
+ }
+ return new;
+}
+#endif
+
void *ass_aligned_alloc(size_t alignment, size_t size)
{
assert(!(alignment & (alignment - 1))); // alignment must be power of 2
#include <assert.h>
#include <errno.h>
+#include "config.h"
+
#ifdef CONFIG_ENCA
#include <enca.h>
#endif
int has_avx2(void);
#endif
+#ifndef HAVE_STRNDUP
+char *ass_strndup(const char *s, size_t n);
+#define strndup ass_strndup
+#endif
+
void *ass_aligned_alloc(size_t alignment, size_t size);
void ass_aligned_free(void *ptr);