Module libc/stdlib

libc/stdlib
Stability: unstable — a raw C binding, not a Yo design. Callers in `std/` take narrow slices of it: `getenv` / `setenv` / `unsetenv` / `realpath` for `std/env`, `exit` for `std/process`, `atof` for `std/encoding/json`'s number parser. Those modules are the supported surface. `malloc` / `free` / `realloc` are bound but are NOT how Yo allocates — that is `std/allocator` and the runtime's own allocator — and calling them on a Yo-owned pointer is a heap bug. Freezing follows the modules above it; the binding set itself is additive-by-demand. — stable modules only change additively; this one may still change.

C11 <stdlib.h> — general utility functions.

Stability

unstable — a raw C binding, not a Yo design. Callers in std/ take narrow slices of it: getenv / setenv / unsetenv / realpath for std/env, exit for std/process, atof for std/encoding/json's number parser. Those modules are the supported surface. malloc / free / realloc are bound but are NOT how Yo allocates — that is std/allocator and the runtime's own allocator — and calling them on a Yo-owned pointer is a heap bug. Freezing follows the modules above it; the binding set itself is additive-by-demand.

Types

div_t type-alias
div_t
ldiv_t type-alias
ldiv_t
lldiv_t type-alias
lldiv_t
wchar_t type-alias
wchar_t

Functions

exit function
fn(status : int) -> unit

Parameters

NameTypeNotes
statusint

Returns: unit

quick_exit function
fn(status : int) -> unit

Parameters

NameTypeNotes
statusint

Returns: unit

_Exit function
fn(status : int) -> unit

Parameters

NameTypeNotes
statusint

Returns: unit

abort function
fn() -> unit

Returns: unit

atexit function
fn(func : fn() -> unit) -> int

Parameters

NameTypeNotes
funcfn() -> unit

Returns: int

at_quick_exit function
fn(func : fn() -> unit) -> int

Parameters

NameTypeNotes
funcfn() -> unit

Returns: int

malloc function
fn(size : usize) -> ?(*(void))

Parameters

NameTypeNotes
sizeusize

Returns: ?(*(void))

calloc function
fn(nmemb : usize, size : usize) -> ?(*(void))

Parameters

NameTypeNotes
nmembusize
sizeusize

Returns: ?(*(void))

realloc function
fn(ptr : ?(*(void)), size : usize) -> ?(*(void))

Parameters

NameTypeNotes
ptr?(*(void))
sizeusize

Returns: ?(*(void))

free function
fn(ptr : ?(*(void))) -> unit

Parameters

NameTypeNotes
ptr?(*(void))

Returns: unit

aligned_alloc function
fn(alignment : usize, size : usize) -> ?(*(void))

C11 aligned_alloc, released with free. Raw and non-portable: it is absent from the Windows CRT (which offers _aligned_malloc / _aligned_free instead), so a call to it does not compile for the *-pc-windows-* targets, and C11 leaves the result undefined unless alignment is a supported power of two and size is a multiple of it (macOS enforces both by returning NULL; glibc enforces neither). GlobalAllocator.aligned_alloc / aligned_free in std/allocator is the portable pair.

Parameters

NameTypeNotes
alignmentusize
sizeusize

Returns: ?(*(void))

atof function
fn(nptr : *(char)) -> f64

Parameters

NameTypeNotes
nptr*(char)

Returns: f64

atoi function
fn(nptr : *(char)) -> int

Parameters

NameTypeNotes
nptr*(char)

Returns: int

atol function
fn(nptr : *(char)) -> long

Parameters

NameTypeNotes
nptr*(char)

Returns: long

atoll function
fn(nptr : *(char)) -> longlong

Parameters

NameTypeNotes
nptr*(char)

Returns: longlong

strtol function
fn(nptr : *(char), endptr : ?(*(?(*(char)))), base : int) -> long

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))
baseint

Returns: long

strtoll function
fn(nptr : *(char), endptr : ?(*(?(*(char)))), base : int) -> longlong

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))
baseint

Returns: longlong

strtoul function
fn(nptr : *(char), endptr : ?(*(?(*(char)))), base : int) -> ulong

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))
baseint

Returns: ulong

strtoull function
fn(nptr : *(char), endptr : ?(*(?(*(char)))), base : int) -> ulonglong

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))
baseint

Returns: ulonglong

strtof function
fn(nptr : *(char), endptr : ?(*(?(*(char))))) -> f32

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))

Returns: f32

strtod function
fn(nptr : *(char), endptr : ?(*(?(*(char))))) -> f64

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))

Returns: f64

strtold function
fn(nptr : *(char), endptr : ?(*(?(*(char))))) -> longdouble

Parameters

NameTypeNotes
nptr*(char)
endptr?(*(?(*(char))))

Returns: longdouble

rand function
fn() -> int

Returns: int

srand function
fn(seed : uint) -> unit

Parameters

NameTypeNotes
seeduint

Returns: unit

rand_r function
fn(seedp : *(uint)) -> int

Parameters

NameTypeNotes
seedp*(uint)

Returns: int

bsearch function
fn(key : *(void), base : *(void), nmemb : usize, size : usize, compar : fn(a : *(void), b : *(void)) -> int) -> ?(*(void))

Parameters

NameTypeNotes
key*(void)
base*(void)
nmembusize
sizeusize
comparfn(a : *(void), b : *(void)) -> int

Returns: ?(*(void))

qsort function
fn(base : *(void), nmemb : usize, size : usize, compar : fn(a : *(void), b : *(void)) -> int) -> unit

Parameters

NameTypeNotes
base*(void)
nmembusize
sizeusize
comparfn(a : *(void), b : *(void)) -> int

Returns: unit

abs function
fn(j : int) -> int

Parameters

NameTypeNotes
jint

Returns: int

labs function
fn(j : long) -> long

Parameters

NameTypeNotes
jlong

Returns: long

llabs function
fn(j : longlong) -> longlong

Parameters

NameTypeNotes
jlonglong

Returns: longlong

div function
fn(numer : int, denom : int) -> div_t

Parameters

NameTypeNotes
numerint
denomint

Returns: div_t

ldiv function
fn(numer : long, denom : long) -> ldiv_t

Parameters

NameTypeNotes
numerlong
denomlong

Returns: ldiv_t

lldiv function
fn(numer : longlong, denom : longlong) -> lldiv_t

Parameters

NameTypeNotes
numerlonglong
denomlonglong

Returns: lldiv_t

getenv function
fn(name : *(char)) -> ?(*(char))

Parameters

NameTypeNotes
name*(char)

Returns: ?(*(char))

setenv function
fn(name : *(char), value : *(char), overwrite : int) -> int

Parameters

NameTypeNotes
name*(char)
value*(char)
overwriteint

Returns: int

unsetenv function
fn(name : *(char)) -> int

Parameters

NameTypeNotes
name*(char)

Returns: int

realpath function
fn(path : *(char), resolved_path : ?(*(char))) -> ?(*(char))

Parameters

NameTypeNotes
path*(char)
resolved_path?(*(char))

Returns: ?(*(char))

system function
fn(command : ?(*(char))) -> int

Parameters

NameTypeNotes
command?(*(char))

Returns: int

getenv_s function
fn(len : ?(*(usize)), value : *(char), maxsize : usize, name : *(char)) -> int

Parameters

NameTypeNotes
len?(*(usize))
value*(char)
maxsizeusize
name*(char)

Returns: int

mblen function
fn(s : ?(*(char)), n : usize) -> int

Parameters

NameTypeNotes
s?(*(char))
nusize

Returns: int

mbtowc function
fn(pwc : ?(*(wchar_t)), s : ?(*(char)), n : usize) -> int

Parameters

NameTypeNotes
pwc?(*(wchar_t))
s?(*(char))
nusize

Returns: int

wctomb function
fn(s : ?(*(char)), wc : wchar_t) -> int

Parameters

NameTypeNotes
s?(*(char))
wcwchar_t

Returns: int

mbstowcs function
fn(dest : ?(*(wchar_t)), src : *(char), n : usize) -> usize

Parameters

NameTypeNotes
dest?(*(wchar_t))
src*(char)
nusize

Returns: usize

wcstombs function
fn(dest : ?(*(char)), src : *(wchar_t), n : usize) -> usize

Parameters

NameTypeNotes
dest?(*(char))
src*(wchar_t)
nusize

Returns: usize

mbstowcs_s function
fn(retval : ?(*(usize)), dest : ?(*(wchar_t)), destsz : usize, src : *(char), len : usize) -> int

Parameters

NameTypeNotes
retval?(*(usize))
dest?(*(wchar_t))
destszusize
src*(char)
lenusize

Returns: int

wcstombs_s function
fn(retval : ?(*(usize)), dest : ?(*(char)), destsz : usize, src : *(wchar_t), len : usize) -> int

Parameters

NameTypeNotes
retval?(*(usize))
dest?(*(char))
destszusize
src*(wchar_t)
lenusize

Returns: int

Constants

EXIT_SUCCESS constant int

Value: <unknown: int>

EXIT_FAILURE constant int

Value: <unknown: int>

RAND_MAX constant int

Value: <unknown: int>

MB_CUR_MAX constant int

Value: <unknown: int>