ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Referência de fonte: GAMES/DOOM/W_FILE.CC

Referência de fonte: GAMES/DOOM/W_FILE.CC

Registro determinístico da fonte. O conteúdo completo do arquivo é reproduzido abaixo; esta página não substitui a interpretação arquitetural dos capítulos autorais.

Identidade do arquivo

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

Dependências sintáticas detectadas

Linha Include
— Nenhum include de preprocessor detectado.

Símbolos detectados

Linha Símbolo
39 W_CloseFile
46 W_Read
59 W_FileLength

Fonte completa

O bloco seguinte é o arquivo textual integral na revisão indicada. Não há elisão, abreviação ou paráfrase.

/* 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;
}

Papel deste registro

O atlas garante rastreabilidade arquivo-a-arquivo. Responsabilidade, invariantes, ownership, concorrência, segurança, desempenho e interação entre subsistemas pertencem aos capítulos autorais e devem citar este arquivo quando aplicável.

Registro do documento ID: source-b9364c11295c2af5 Reviewed source: da3df29cb397 Class: generated-source-reference