Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

strndup

string.strndup
fn strndup(str: [*:0]const c_char, n: usize) callconv(.c) ?[*:0]c_char

File

lib/c/string.zig:179

Code

fn strndup(str: [*:0]const c_char, n: usize) callconv(.c) ?[*:0]c_char {
    const len = strnlen(str, n);
    const d_opaque = c.malloc(len + 1) orelse return null;
    const d: [*]c_char = @ptrCast(d_opaque);
    @memcpy(d[0..len], str[0..len]);
    d[len] = 0;
    return @ptrCast(d);
}