summaryrefslogtreecommitdiffstats
path: root/libass/ass_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r--libass/ass_utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index 72993d7..e119c02 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -18,8 +18,10 @@
#include "config.h"
+#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <inttypes.h>
#include <strings.h>
@@ -63,6 +65,29 @@ int has_avx2(void)
#endif // ASM
+void *ass_aligned_alloc(size_t alignment, size_t size)
+{
+ if (alignment & (alignment - 1))
+ abort(); // not a power of 2
+ if (size >= SIZE_MAX - alignment - sizeof(void *))
+ return NULL;
+ char *allocation = malloc(size + sizeof(void *) + alignment - 1);
+ if (!allocation)
+ return NULL;
+ char *ptr = allocation + sizeof(void *);
+ unsigned int misalign = (uintptr_t)ptr & (alignment - 1);
+ if (misalign)
+ ptr += alignment - misalign;
+ *((void **)ptr - 1) = allocation;
+ return ptr;
+}
+
+void ass_aligned_free(void *ptr)
+{
+ if (ptr)
+ free(*((void **)ptr - 1));
+}
+
int mystrtoi(char **p, int *res)
{
double temp_res;