ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Source reference: GAMES/DOOM/W_FILE.CC

Source reference: GAMES/DOOM/W_FILE.CC

Deterministic source record. The complete textual file is reproduced below; this page does not replace architectural interpretation in the authored chapters.

File identity

Field Value
Path GAMES/DOOM/W_FILE.CC
Lines 64
Bytes 1367
SHA-256 b9364c11295c2af55902775a678679b53c07f5711dee68fea3dd6797fd21cafa
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Detected syntactic dependencies

Line Include
— No preprocessor include detected.

Detected symbols

Line Symbol
39 W_CloseFile
46 W_Read
59 W_FileLength

Complete source

The following block is the complete textual file at the recorded revision. No lines are elided, abbreviated or paraphrased.

/* ChrisC WAD file: fopen/fseek/fread, int fds, layout matches wad_file_t. */

struct chris_wad {
    char *file_class;
    char *mapped;
    int length;
    int fd;
};

typedef struct chris_wad chris_wad_t;

struct chris_wad *W_OpenFile(char *path) {
    struct chris_wad *w;
    int fd;
    int len;
    fd = fopen(path);
    if (fd < 0)
        return 0;
    len = fsize(path);
    printf("W_OpenFile %s fd=%d len=%d\n", path, fd, len);
    w = malloc(sizeof(chris_wad_t));
    if (!w) {
        fclose(fd);
        return 0;
    }
    w->file_class = 0;
    w->mapped = 0;
    w->length = len > 0 ? len : 0;
    if (w->length == 0) {
        printf("W_OpenFile invalid size=%d\n", len);
        fclose(fd);
        free(w);
        return 0;
    }
    w->fd = fd;
    return w;
}

void W_CloseFile(struct chris_wad *wad) {
    if (!wad)
        return;
    fclose(wad->fd);
    free(wad);
}

int W_Read(struct chris_wad *wad, int offset, char *buffer, int buffer_len) {
    int n;
    if (!wad)
        return 0;
    fseek(wad->fd, offset);
    n = fread(wad->fd, buffer, buffer_len);
    if (offset == 0 && buffer_len >= 4) {
        printf("W_Read hdr %d bytes: %c%c%c%c\n", n, buffer[0], buffer[1],
               buffer[2], buffer[3]);
    }
    return n;
}

int W_FileLength(struct chris_wad *wad) {
    if (!wad)
        return 0;
    return wad->length;
}

Role of this record

The atlas guarantees file-by-file traceability. Responsibility, invariants, ownership, concurrency, security, performance and subsystem interactions belong in authored chapters and must cite this file when applicable.

Document record ID: source-b9364c11295c2af5 Reviewed source: da3df29cb397 Class: generated-source-reference