cstr
byte primitives on raw :cstr values.
Since: 2026-07-01
cstr-len
(cstr-len [s : cstr] :)
byte length of a NUL-terminated C string.
| s | NUL-terminated C string pointer |
Length in bytes, excluding the trailing NUL.
(cstr-len "hello") ; => 5
cstr-nth
(cstr-nth [s : cstr i : int] :)
byte at index i in a NUL-terminated C string.
| s | NUL-terminated C string pointer | |
| i | zero-based byte index; caller must ensure 0 <= i < (cstr-len s) |
The unsigned byte value at position i.
(cstr-nth "1+2" 1) ; => 43 ('+')
cstr-sub
(cstr-sub [s : cstr start : int end : int] :)
substring [start, end) of a NUL-terminated C string.
| s | NUL-terminated C string pointer | |
| start | zero-based start byte index (clamped into [0, len]) | |
| end | exclusive end byte index (clamped into [start, len]) |
A freshly heap-allocated cstr holding the bytes of s in [start, end), NUL-terminated. Out-of-range indices are clamped, so the result is always a valid (possibly empty) string. The caller frees the result.
(cstr-sub "hello" 1 4) ; => "ell"
cstr-eq?
(cstr-eq? [a : cstr b : cstr] :)
content equality on two NUL-terminated C strings.
| a | NUL-terminated C string pointer, or NULL | |
| b | NUL-terminated C string pointer, or NULL |
true when both are NULL, or both are non-NULL and hold the same bytes up to the terminator. false otherwise -- in particular a NULL never equals a non-NULL, including the empty string.
(cstr-eq? "abc" (cstr-sub "abcdef" 0 3)) ; => true (cstr-eq? "abc" "abd") ; => false
cstr-free
(cstr-free [s : cstr] :)
release a cstr this module heap-allocated.
| s | a cstr returned by cstr-sub, or NULL |
(let [t (cstr-sub "hello world" 0 5)]
(println t)
(cstr-free t))