int Ram_read(Ram * ram,size_t iter) { if(iter>=ram->memsize) { // avoid SIGSEGV iter=ram->memsize-1; } if(iter < ram->regs_count) { return Register_read(ram->regs[iter]); } iter-=ram->regs_count; return ram->mem[iter]; }
/** * Commits the amount given by need to the buffer, moving the internal * counters around so that the next read starts after the need point. * You use this after you're done working with the data and want to * do the next read. */ int IOBuf_read_commit(IOBuf *buf, int need) { buf->avail -= need; assert(buf->avail >= 0 && "Buffer commit reduced avail to < 0."); check(Register_read(buf->fd, need) != -1, "Failed to record read, must have died."); buf->mark = 0; if(buf->avail == 0) { // if there's nothing available then just start at the beginning buf->cur = 0; } else { buf->cur += need; } return 0; error: return -1; }