Skip to content

Libc Rt Freestanding

Spice
import "std/runtime/libc_rt_freestanding";

Functions

memcpy

Spice
public f<byte*> memcpy(byte* dest, const byte* src, unsigned long size)

Copy size bytes from src to dest. The memory areas must not overlap

Parameters

Name Type Description
dest byte* Destination memory area
src const byte* Source memory area
size unsigned long Number of bytes

Returns: byte* — Destination memory area

memmove

Spice
public f<byte*> memmove(byte* dest, const byte* src, unsigned long size)

Copy size bytes from src to dest. The memory areas may overlap

Parameters

Name Type Description
dest byte* Destination memory area
src const byte* Source memory area
size unsigned long Number of bytes

Returns: byte* — Destination memory area

memset

Spice
public f<byte*> memset(byte* dest, int value, unsigned long size)

Fill size bytes of dest with the given value

Parameters

Name Type Description
dest byte* Destination memory area
value int Value, of which the lowest byte is used
size unsigned long Number of bytes

Returns: byte* — Destination memory area

memcmp

Spice
public f<int> memcmp(const byte* lhs, const byte* rhs, unsigned long size)

Compare size bytes of two memory areas

Parameters

Name Type Description
lhs const byte* First memory area
rhs const byte* Second memory area
size unsigned long Number of bytes

Returns: int — 0 if equal, a negative value if the first differing byte is smaller in lhs, a positive value otherwise

bcmp

Spice
public f<int> bcmp(const byte* lhs, const byte* rhs, unsigned long size)

Check if two memory areas are equal. LLVM turns memcmp calls, of which only the equality is used, into bcmp calls

Parameters

Name Type Description
lhs const byte* First memory area
rhs const byte* Second memory area
size unsigned long Number of bytes

Returns: int — 0 if equal, another value otherwise

strlen

Spice
public f<unsigned long> strlen(string str)

Get the length of a null-terminated string

Parameters

Name Type Description
str string String

Returns: unsigned long — Number of chars before the null terminator

strcmp

Spice
public f<int> strcmp(string lhs, string rhs)

Compare two null-terminated strings

Parameters

Name Type Description
lhs string First string
rhs string Second string

Returns: int — 0 if equal, a negative value if the first differing char is smaller in lhs, a positive value otherwise