Skip to content

StrDup

Description

Short alias for StrInitFromStr. Deep-copies an existing Str by value; 1-arg form uses MisraScope, 2-arg form takes an explicit allocator. Use when reading at the call site as “duplicate this string” is clearer than the longer name.

Success

Returns a usable Str holding an independent copy of the source’s contents.

Failure

Returns an empty Str on allocator OOM. LOG_FATAL if the source handle is invalid.

Usage example (Cross-references)

Usage examples (Cross-references)
        response->content_type = HTTP_CONTENT_TYPE_TEXT_HTML;
        StrDeinit(&response->body);
        response->body = StrDup(html, response->allocator);
        return response;
    }
    // Test StrDup function (alias for StrInitFromStr)
    bool test_str_dup(void) {
        WriteFmt("Testing StrDup\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str src = StrInitFromZstr("Hello, World!", &alloc);
        Str dst = StrDup(&src, &alloc);
    
        // Validate both strings
Last updated on