summaryrefslogtreecommitdiffstats
path: root/libass/ass_utils.c
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2020-12-16 22:12:14 +0100
committerOneric <oneric@oneric.stub>2021-03-28 22:42:16 +0200
commit43af8f7b3b0ec43723a256ec04de3a571ebf0117 (patch)
tree6e7e0230670b68a2ddf997d05ecd21c379a272af /libass/ass_utils.c
parent11493fbde283dc712cc45df9ceb209a1833c9a7f (diff)
downloadlibass-43af8f7b3b0ec43723a256ec04de3a571ebf0117.tar.bz2
libass-43af8f7b3b0ec43723a256ec04de3a571ebf0117.tar.xz
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.
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r--libass/ass_utils.c14
1 files changed, 13 insertions, 1 deletions
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;