Skip to main content

check_dump_file

Function check_dump_file 

Source
pub fn check_dump_file(
    file: &str,
    sbuf: &Metadata,
    name: &str,
    test_only: bool,
) -> Option<(eprog, i32)>
Expand description

Port of Eprog check_dump_file(char *file, struct stat *sbuf, char *name, int *ksh, int test_only) from Src/parse.c:3833. Walks the dumps mmap list looking for (dev, ino) matching sbuf; on miss, calls load_dump_header to read the .zwc header. Then dump_find_func(d, name) locates the function table entry. Returns the wordcode slice + ksh-load flag.

Eprog
check_dump_file(char *file, struct stat *sbuf, char *name,
                int *ksh, int test_only)
{
    int isrec = 0;
    Wordcode d;
    FDHead h;
    FuncDump f;
    struct stat lsbuf;
    if (!sbuf) {
        if (zwcstat(file, &lsbuf)) return NULL;
        sbuf = &lsbuf;
    }
  rec:
    d = NULL;
    for (f = dumps; f; f = f->next)
        if (f->dev == sbuf->st_dev && f->ino == sbuf->st_ino)
            { d = f->map; break; }
    if (!f && (isrec || !(d = load_dump_header(NULL, file, 0))))
        return NULL;
    if ((h = dump_find_func(d, name))) {
        if (test_only) return &dummy_eprog;
        /* allocate Eprog from f->map at h offset, incrdumpcount,
           return prog */
    }
    return NULL;
}

Rust port returns Option<(eprog, i32)> instead of the C Eprog pointer + *ksh out-param: tuple element 0 is the loaded program (wordcode + string table per the fdhead record), element 1 is the ksh-load mode exactly as C writes *ksh: FDHF_KSHLOAD → 2, FDHF_ZSHLOAD → 0, neither → 1 (c:3954-3956).