Skip to content

Commit 304a28a

Browse files
committed
mimalloc: add strdup and strndup overrride
1 parent a3e91de commit 304a28a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/mimalloc.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ pub export fn c_alloc(nmemb: usize, size: usize) callconv(.C) ?*anyopaque {
4242
return c.mi_heap_calloc(heap.?, nmemb, size);
4343
}
4444

45+
pub export fn str_dup(s: [*c]const u8) callconv(.C) [*c]u8 {
46+
if (heap == null) return null;
47+
return c.mi_heap_strdup(heap.?, s);
48+
}
49+
50+
pub export fn strn_dup(s: [*c]const u8, size: usize) callconv(.C) [*c]u8 {
51+
if (heap == null) return null;
52+
return c.mi_heap_strndup(heap.?, s, size);
53+
}
54+
4555
// NOOP, use destroy to clear all the memory allocated at once.
4656
pub export fn f_ree(_: ?*anyopaque) callconv(.C) void {
4757
return;

0 commit comments

Comments
 (0)