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.

dup2

linux.dup2
pub fn dup2(old: fd_t, new: fd_t) usize

File

lib/std/os/linux.zig:769

Code

pub fn dup2(old: fd_t, new: fd_t) usize {
    if (@hasField(SYS, "dup2")) {
        return syscall2(.dup2, @as(u32, @bitCast(old)), @as(u32, @bitCast(new)));
    } else {
        if (old == new) {
            if (std.debug.runtime_safety) {
                const rc = fcntl(F.GETFD, @as(fd_t, old), 0);
                if (@as(isize, @bitCast(rc)) < 0) return rc;
            }
            return @as(usize, @intCast(old));
        } else {
            return syscall3(.dup3, @as(u32, @bitCast(old)), @as(u32, @bitCast(new)), 0);
        }
    }
}