|
1 | 1 | // Copyright (c) 2022-present INESC-ID. |
2 | 2 | // Distributed under the MIT license that can be found in the LICENSE file. |
3 | 3 |
|
4 | | -use std::ffi::{c_char, c_void}; |
5 | | - |
6 | | -unsafe extern "C" { |
7 | | - fn malloc(size: usize) -> *mut c_void; |
8 | | - fn free(ptr: *mut c_void); |
9 | | - fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void; |
10 | | - fn calloc(nmemb: usize, size: usize) -> *mut c_void; |
11 | | - fn strdup(s: *const c_char) -> *mut c_char; |
12 | | -} |
13 | | - |
14 | 4 | /// # Safety |
15 | 5 | /// |
16 | 6 | /// Same contract as C's `malloc`. |
17 | | -pub unsafe fn malloc_unsafe(a0: u64) -> *mut c_void { |
18 | | - unsafe { malloc(a0 as usize) } |
| 7 | +pub unsafe fn malloc_unsafe(a0: u64) -> *mut libc::c_void { |
| 8 | + unsafe { libc::malloc(a0 as libc::size_t) } |
19 | 9 | } |
20 | 10 |
|
21 | 11 | /// # Safety |
22 | 12 | /// |
23 | 13 | /// Same contract as C's `free`. |
24 | | -pub unsafe fn free_unsafe(a0: *mut c_void) { |
25 | | - unsafe { free(a0) } |
| 14 | +pub unsafe fn free_unsafe(a0: *mut libc::c_void) { |
| 15 | + unsafe { libc::free(a0) } |
26 | 16 | } |
27 | 17 |
|
28 | 18 | /// # Safety |
29 | 19 | /// |
30 | 20 | /// Same contract as C's `realloc`. |
31 | | -pub unsafe fn realloc_unsafe(a0: *mut c_void, a1: u64) -> *mut c_void { |
32 | | - unsafe { realloc(a0, a1 as usize) } |
| 21 | +pub unsafe fn realloc_unsafe(a0: *mut libc::c_void, a1: u64) -> *mut libc::c_void { |
| 22 | + unsafe { libc::realloc(a0, a1 as libc::size_t) } |
33 | 23 | } |
34 | 24 |
|
35 | 25 | /// # Safety |
36 | 26 | /// |
37 | 27 | /// Same contract as C's `calloc`. |
38 | | -pub unsafe fn calloc_unsafe(a0: u64, a1: u64) -> *mut c_void { |
39 | | - unsafe { calloc(a0 as usize, a1 as usize) } |
| 28 | +pub unsafe fn calloc_unsafe(a0: u64, a1: u64) -> *mut libc::c_void { |
| 29 | + unsafe { libc::calloc(a0 as libc::size_t, a1 as libc::size_t) } |
40 | 30 | } |
41 | 31 |
|
42 | 32 | /// # Safety |
43 | 33 | /// |
44 | 34 | /// Same contract as C's `strdup`. |
45 | 35 | pub unsafe fn strdup_unsafe(a0: *const u8) -> *mut u8 { |
46 | | - unsafe { strdup(a0 as *const c_char) as *mut u8 } |
| 36 | + unsafe { libc::strdup(a0 as *const libc::c_char) as *mut u8 } |
47 | 37 | } |
0 commit comments