Skip to content
StrTryInitFromCstr

StrTryInitFromCstr

Description

Initialise *out as a Str holding len bytes copied from cstr, allocated through allocator_ptr (accepts a typed allocator handle or a raw Allocator *).

Success

Returns true. *out is a usable Str holding the copied bytes; trailing NUL written at out->data[len].

Failure

Returns false on allocator OOM. *out is left as an empty Str bound to the allocator. LOG_FATAL if out or cstr is NULL.

Usage example (Cross-references)

Usage examples (Cross-references)
        MemSet(&entry, 0, sizeof(entry));
    
        if (!StrTryInitFromCstr(&entry.module_path, module_path, ZstrLen(module_path), self->allocator)) {
            return NULL;
        }
        MemSet(&entry, 0, sizeof(entry));
    
        if (!StrTryInitFromCstr(&entry.module_path, module_path, ZstrLen(module_path), self->allocator)) {
            return NULL;
        }
Last updated on