comparison mupdf-source/thirdparty/extract/src/mem.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 #include "extract/alloc.h"
2
3 #include "mem.h"
4
5 #include <assert.h>
6 #include <stdio.h>
7 #include <string.h>
8
9 #include "compat_va_copy.h"
10
11
12 void extract_bzero(void *b, size_t len)
13 {
14 memset(b, 0, len);
15 }
16
17 int extract_vasprintf(extract_alloc_t *alloc, char **out, const char *format, va_list va)
18 {
19 int n;
20 int ret;
21 va_list va2;
22
23 va_copy(va2, va);
24 n = vsnprintf(NULL, 0, format, va);
25 if (n < 0)
26 {
27 ret = n;
28 goto end;
29 }
30 if (extract_malloc(alloc, out, n + 1))
31 {
32 ret = -1;
33 goto end;
34 }
35 vsnprintf(*out, n + 1, format, va2);
36
37 ret = 0;
38 end:
39
40 va_end(va2);
41
42 return ret;
43 }
44
45
46 int extract_asprintf(extract_alloc_t *alloc, char **out, const char *format, ...)
47 {
48 va_list va;
49 int ret;
50
51 va_start(va, format);
52 ret = extract_vasprintf(alloc, out, format, va);
53 va_end(va);
54
55 return ret;
56 }
57
58 int extract_strdup(extract_alloc_t *alloc, const char *s, char **o_out)
59 {
60 size_t l = strlen(s) + 1;
61
62 if (extract_malloc(alloc, o_out, l)) return -1;
63 memcpy(*o_out, s, l);
64
65 return 0;
66 }