From 43af8f7b3b0ec43723a256ec04de3a571ebf0117 Mon Sep 17 00:00:00 2001 From: Oneric Date: Wed, 16 Dec 2020 22:12:14 +0100 Subject: Add strdup fallback And move fallback declarations to ass_compat.h As ass_compat.h is already included in every source file we no longer need to include _both_ string.h and ass_utils.h to use str(n)dup. Definitions are still in ass_utils.c since a separate source file just for two functions seemed overkill. --- libass/ass_utils.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'libass/ass_utils.c') diff --git a/libass/ass_utils.c b/libass/ass_utils.c index 7fba778..65b6f74 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -66,8 +66,20 @@ int has_avx2(void) #endif // ASM +// Fallbacks +#ifndef HAVE_STRDUP +char *ass_strdup_fallback(const char *str) +{ + size_t len = strlen(str) + 1; + char *new_str = malloc(len); + if (new_str) + memcpy(new_str, str, len); + return new_str; +} +#endif + #ifndef HAVE_STRNDUP -char *ass_strndup(const char *s, size_t n) +char *ass_strndup_fallback(const char *s, size_t n) { char *end = memchr(s, 0, n); size_t len = end ? end - s : n; -- cgit v1.2.3