Axle v0.14.1
Package

std/ffi/libc/mem

libc memory primitives. All bindings use @link(symbol = …) to resolve
directly against libc — no Rust wrapper. Callers wrap usage in
unsafe { } blocks.

Reference: https://en.cppreference.com/w/c/memory

Free functions

TypeMethod and description
ptr
libc_malloc(n : i64) : ptr Allocate n uninitialised bytes. Returns the block, or NULL on failure.
Free with libc_free. @param n size in bytes.
ptr
libc_calloc(count : i64, size : i64) : ptr Allocate count * size bytes, zero-initialised. Returns the block, or
NULL on failure. @param size size of one element, in bytes.
ptr
libc_realloc(p : ptr, n : i64) : ptr Resize the block p to n bytes, preserving existing contents. Returns
the (possibly moved) block, or NULL on failure (leaving p valid).
void
libc_free(p : ptr) : void Release a block previously returned by libc_malloc / libc_calloc /
libc_realloc. A NULL p is a no-op.
ptr
libc_memcpy(dst : ptr, src : ptr, n : i64) : ptr Copy n bytes from src to dst; the regions must not overlap.
ptr
libc_memmove(dst : ptr, src : ptr, n : i64) : ptr Copy n bytes from src to dst, overlap-safe.
ptr
libc_memset(dst : ptr, c : i32, n : i64) : ptr Fill n bytes of dst with the low byte of c.
i32
libc_memcmp(a : ptr, b : ptr, n : i64) : i32 Compare n bytes of a and b lexicographically.
i64
libc_strlen(s : ptr) : i64 Length in bytes of the NUL-terminated C string at s (excluding the NUL).
i32
libc_strcmp(a : ptr, b : ptr) : i32 Compare two NUL-terminated C strings lexicographically.
i32
libc_strncmp(a : ptr, b : ptr, n : i64) : i32 Compare at most n bytes of two NUL-terminated C strings lexicographically.

Method detail

#libc_malloc

libc_malloc(n : i64) : ptr

Allocate n uninitialised bytes. Returns the block, or NULL on failure.
Free with libc_free. @param n size in bytes.

#libc_calloc

libc_calloc(count : i64, size : i64) : ptr

Allocate count * size bytes, zero-initialised. Returns the block, or
NULL on failure. @param size size of one element, in bytes.

Parameters
count number of elements to allocate.

#libc_realloc

libc_realloc(p : ptr, n : i64) : ptr

Resize the block p to n bytes, preserving existing contents. Returns
the (possibly moved) block, or NULL on failure (leaving p valid).

Parameters
p block to resize, from a prior libc allocation (caller-managed).
n new size in bytes.

#libc_free

libc_free(p : ptr) : void

Release a block previously returned by libc_malloc / libc_calloc /
libc_realloc. A NULL p is a no-op.

Parameters
p block to release; ownership returns to the allocator.

#libc_memcpy

libc_memcpy(dst : ptr, src : ptr, n : i64) : ptr

Copy n bytes from src to dst; the regions must not overlap.

Parameters
dst destination buffer (caller-managed).
src source buffer (caller-managed).
n byte count. @return dst.

#libc_memmove

libc_memmove(dst : ptr, src : ptr, n : i64) : ptr

Copy n bytes from src to dst, overlap-safe.

Parameters
dst destination buffer (caller-managed).
src source buffer (caller-managed).
n byte count. @return dst.

#libc_memset

libc_memset(dst : ptr, c : i32, n : i64) : ptr

Fill n bytes of dst with the low byte of c.

Parameters
dst destination buffer (caller-managed).
c fill value; only its low byte is used.
n byte count. @return dst.

#libc_memcmp

libc_memcmp(a : ptr, b : ptr, n : i64) : i32

Compare n bytes of a and b lexicographically.

Parameters
a first buffer (caller-managed).
b second buffer (caller-managed).
n byte count. @return <0, 0, or >0.

#libc_strlen

libc_strlen(s : ptr) : i64

Length in bytes of the NUL-terminated C string at s (excluding the NUL).

Parameters
s pointer to a NUL-terminated C string (caller-managed).

#libc_strcmp

libc_strcmp(a : ptr, b : ptr) : i32

Compare two NUL-terminated C strings lexicographically.

Parameters
a first NUL-terminated C string (caller-managed).
b second NUL-terminated C string (caller-managed).
Returns <0, 0, or >0.

#libc_strncmp

libc_strncmp(a : ptr, b : ptr, n : i64) : i32

Compare at most n bytes of two NUL-terminated C strings lexicographically.

Parameters
a first NUL-terminated C string (caller-managed).
b second NUL-terminated C string (caller-managed).
n maximum bytes to compare. @return <0, 0, or >0.