Skip to content

IterCarve

Description

Carve a child iterator from a parent. The child starts at the parent’s current position with length n (so its valid range is the parent’s [pos, pos + n)), pos 0, inheriting the parent’s alignment and direction. The parent is unchanged – after the sub-read returns, the parent can keep iterating from where it left off.

Parameters

Name Direction Description
parent in Source iterator. Must outlive the child read.
n in Number of elements the child can read.

Success

Returns a typed compound-literal Iter covering [parent->data + parent->pos, parent->data + parent->pos + n), with pos = 0 and parent’s alignment / dir. Parent is unchanged.

Failure

Macro cannot fail. Caller is responsible for not passing an n that extends past the parent’s remaining range; no bounds check is performed.

Usage example (Cross-references)

Usage examples (Cross-references)
            // `sec_it` is carved at exactly SECT64_SIZE bytes, so the two
            // 16-byte moves below stay inside its window.
            BufIter      sec_it = IterCarve(cmd, SECT64_SIZE);
            MachoSection sec;
            MemSet(&sec, 0, sizeof(sec));
            }
            // Peek the prefix (cmd, cmdsize) without advancing the walker.
            BufIter prefix = IterCarve(&walker, 8);
            u32     cmd, cmdsize;
            if (!BufReadFmt(&prefix, FMT_MACHO_LC_PREFIX_LE, cmd, cmdsize)) {
            // Carve a view of this entire command (including the 8-byte
            // prefix) for the sub-decoder. The walker stays put.
            BufIter cmd_view = IterCarve(&walker, cmdsize);
            u32     type     = cmd & ~LC_REQ_DYLD;
            switch (type) {
        BufIter  parent = BufIterFromMemory(buf, 4);
        IterMove(&parent, 1); // parent cursor at index 1
        BufIter child = IterCarve(&parent, 2);
        if (IterRemainingLength(&child) != 2 || IterIndex(&child) != 0) {
            return false;
Last updated on