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

Referência de fonte: LIB/STDLIB.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 LIB/STDLIB.CC
Lines 113
Bytes 1716
SHA-256 7f2c20c5f53ab484b9154a02ac2aade300c19d5a6a85f3485609f62546b6adbe
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Dependências sintáticas detectadas

Linha Include
1 LIB/STDLIB.H

Símbolos detectados

Linha Símbolo
3 abs
8 atoi
23 atof
54 exit
62 abort
87 isatty
92 system
97 close
102 mkdir
108 stat

Fonte completa

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

#include "LIB/STDLIB.H"

int abs(int x) {
    if (x < 0) return -x;
    return x;
}

int atoi(char *s) {
    int v = 0;
    int i = 0;
    int sign = 1;
    if (s[0] == '-') {
        sign = -1;
        i++;
    }
    while (s[i] >= '0' && s[i] <= '9') {
        v = v * 10 + (s[i] - '0');
        i++;
    }
    return sign * v;
}

float atof(char *s) {
    float v;
    float frac;
    float div;
    int i;
    int sign;
    v = 0.0;
    frac = 0.0;
    div = 1.0;
    i = 0;
    sign = 1;
    if (s[0] == '-') {
        sign = -1;
        i = i + 1;
    }
    while (s[i] >= '0' && s[i] <= '9') {
        v = v * 10.0 + (float)(s[i] - '0');
        i = i + 1;
    }
    if (s[i] == '.') {
        i = i + 1;
        while (s[i] >= '0' && s[i] <= '9') {
            frac = frac * 10.0 + (float)(s[i] - '0');
            div = div * 10.0;
            i = i + 1;
        }
        v = v + frac / div;
    }
    return (float)sign * v;
}

void exit(int c) {
    c = c;
    printf("exit %d\n", c);
    for (;;) {
        wait(60);
    }
}

void abort() {
    exit(1);
}

void *calloc(size_t n, size_t sz) {
    int bytes;
    char *p;
    int i;
    bytes = (int)n * (int)sz;
    p = malloc((size_t)bytes);
    if (!p)
        return 0;
    i = 0;
    while (i < bytes) {
        p[i] = 0;
        i = i + 1;
    }
    return p;
}

char *getenv(char *name) {
    name = name;
    return 0;
}

int isatty(int fd) {
    fd = fd;
    return 0;
}

int system(char *cmd) {
    cmd = cmd;
    return -1;
}

int close(int fd) {
    fclose(fd);
    return 0;
}

int mkdir(char *path, int mode) {
    path = path;
    mode = mode;
    return 0;
}

int stat(char *path, int st) {
    path = path;
    st = st;
    return -1;
}

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-7f2c20c5f53ab484 Reviewed source: da3df29cb397 Class: generated-source-reference