StrInitCopy
Description
Deep-copy src into a freshly initialised dst, allocating through src’s inline allocator. Both ends carry independent backing storage afterwards.
Success
Returns true. *dst is a usable Str with the same contents and allocator as *src.
Failure
Returns false on allocator OOM. *dst is left zeroed.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Str.c:122:
}
bool StrInitCopy(Str *dst, const Str *src) {
if (!dst || !src) {
LOG_FATAL("Invalid arguments");- In
Dir.c:47:
dst->type = src->type;
StrInitCopy(&dst->name, &src->name);
return dst;- In
Http.c:46:
dst->value = StrInit((Allocator *)alloc);
if (!StrInitCopy(&dst->key, &src->key)) {
StrDeinit(&dst->key);
return false;- In
Http.c:50:
return false;
}
if (!StrInitCopy(&dst->value, &src->value)) {
StrDeinit(&dst->key);
StrDeinit(&dst->value);- In
Str.Init.c:195:
// Test StrInitCopy function
bool test_str_init_copy(void) {
WriteFmt("Testing StrInitCopy\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Init.c:203:
// Copy src to dst
bool success = StrInitCopy(&dst, &src);
// Validate both strings
- In
Str.Init.c:228:
Str dup = StrInitFromStr(&src, &alloc);
Str dst = StrInit(&alloc);
bool copied = StrInitCopy(&dst, &src);
ValidateStr(&src);
Last updated on