diff options
author | wm4 <wm4@nowhere> | 2014-11-17 21:22:21 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-11-17 21:22:21 +0100 |
commit | 2f9467cfd2574af44f97ee89b460c410a5a3c85a (patch) | |
tree | 2ae50d584c136b84778cff4429ec9dbddf780d6d /libass/ass_utils.c | |
parent | 0c0b3f57aa688f3d2b38c5faf8178dad45302aa0 (diff) | |
download | libass-2f9467cfd2574af44f97ee89b460c410a5a3c85a.tar.bz2 libass-2f9467cfd2574af44f97ee89b460c410a5a3c85a.tar.xz |
Provide a strndup() fallback
This standard function is not available everywhere, so we detect it and
provide a fallback if missing.
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r-- | libass/ass_utils.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c index 593d787c..b1c736c3 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -62,6 +62,20 @@ int has_avx2(void) #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 |