1use super::openjpeg::*;
2
3extern "C" {
4
5 fn malloc(_: usize) -> *mut core::ffi::c_void;
6
7 fn calloc(_: usize, _: usize) -> *mut core::ffi::c_void;
8
9 fn realloc(_: *mut core::ffi::c_void, _: usize) -> *mut core::ffi::c_void;
10
11 fn free(_: *mut core::ffi::c_void);
12
13 fn memcpy(
14 _: *mut core::ffi::c_void,
15 _: *const core::ffi::c_void,
16 _: usize,
17 ) -> *mut core::ffi::c_void;
18}
19
20pub(crate) fn opj_malloc(mut size: size_t) -> *mut core::ffi::c_void {
21 unsafe {
22 if size == 0 {
23 return core::ptr::null_mut::<core::ffi::c_void>();
25 }
26 malloc(size)
27 }
28}
29
30pub(crate) fn opj_calloc(mut num: size_t, mut size: size_t) -> *mut core::ffi::c_void {
31 unsafe {
32 if num == 0 || size == 0 {
33 return core::ptr::null_mut::<core::ffi::c_void>();
35 }
36 calloc(num, size)
37 }
38}
39
40pub(crate) fn opj_realloc(
41 mut ptr: *mut core::ffi::c_void,
42 mut new_size: size_t,
43) -> *mut core::ffi::c_void {
44 unsafe {
45 if new_size == 0 {
46 return core::ptr::null_mut::<core::ffi::c_void>();
48 }
49 realloc(ptr, new_size)
50 }
51}
52
53pub(crate) fn opj_free(mut ptr: *mut core::ffi::c_void) {
54 unsafe {
55 free(ptr);
56 }
57}