Exemple #1
0
record record_stream::get_record() {
        record_t data;
        int res = fread(&data, 1, RECORD_LENGTH, file);
        if (res == 0)
                throw end_stream();
        else if (res < RECORD_LENGTH)
                throw std::runtime_error("Incomplete record");
        rec_idx++;

#if defined(LITTLE_ENDIAN)
        uint8_t* d = (uint8_t*) &data;
        std::swap(d[0], d[5]);
        std::swap(d[1], d[4]);
        std::swap(d[2], d[3]);
#elif defined(BIG_ENDIAN)
#else
#error Either LITTLE_ENDIAN or BIG_ENDIAN must be defined.
#endif

        record rec(data);
        if (rec_idx > 1 && rec.get_wrap_flag())
                time_offset += (1ULL<<TIME_BITS) - 1;
        rec.time_offset = time_offset;
        return rec;
}
Exemple #2
0
void write_record(FILE* fout, record r) {
        record_t data;
        data = r.data;
        data = htobe64(data << 16);

        int res = fwrite(&data, 1, RECORD_LENGTH, fout);
        if (res == 0)
                throw end_stream();
        else if (res < RECORD_LENGTH)
                throw std::runtime_error("Incomplete record written");
}
Exemple #3
0
global Cell *
read_stream(Cell *cell)
{
        long    c;

        c = cell->c_file == stdin ? get_one_char() : GetChar(cell->c_file);
        if (c == EOF) {
                end_stream(cell->c_file);
                return new_cnst(nil);
        }
        return new_cons(cons,
                new_pair(new_char((Char)c), new_stream(cell->c_file)));
}