No matching definitions.

cstr

stdlib/cstr.tur

byte primitives on raw :cstr values.

Since: 2026-07-01

defn

cstr-len

(cstr-len [s : cstr] :)

byte length of a NUL-terminated C string.

sNUL-terminated C string pointer

Length in bytes, excluding the trailing NUL.

(cstr-len "hello")  ; => 5
defn

cstr-nth

(cstr-nth [s : cstr i : int] :)

byte at index i in a NUL-terminated C string.

sNUL-terminated C string pointer
izero-based byte index; caller must ensure 0 <= i < (cstr-len s)

The unsigned byte value at position i.

(cstr-nth "1+2" 1)  ; => 43  ('+')
defn

cstr-sub

(cstr-sub [s : cstr start : int end : int] :)

substring [start, end) of a NUL-terminated C string.

sNUL-terminated C string pointer
startzero-based start byte index (clamped into [0, len])
endexclusive 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"
defn

cstr-eq?

(cstr-eq? [a : cstr b : cstr] :)

content equality on two NUL-terminated C strings.

aNUL-terminated C string pointer, or NULL
bNUL-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
defn

cstr-free

(cstr-free [s : cstr] :)

release a cstr this module heap-allocated.

sa cstr returned by cstr-sub, or NULL
(let [t (cstr-sub "hello world" 0 5)]
    (println t)
    (cstr-free t))