rio.c
// used by rio_readnb and rio_readlineb on the internal rio_buf
// then store everything in usrbuf
used by rio_readnb and rio_readlineb on the internal rio_buf
then store everything in usrbuf
used by rio_readnb and rio_readlineb on the internal rio_buf then store everything in usrbuf
static ssize_t rio_read(struct rio_t *rp, char *usrbuf, size_t n)
{
    while (rp->rio_cnt <= 0) {  
        rp->rio_cnt = read(rp->rio_fd, rp->rio_buf, sizeof(rp->rio_buf));
        if (rp->rio_cnt < 0) {
            if (errno != EINTR) return -1;
        } else if (rp->rio_cnt == 0) {  
            return 0;
        } else {
            rp->rio_bufptr = rp->rio_buf;
        }
    }
    int cnt = rp->rio_cnt < n ? rp->rio_cnt : n;
    memcpy(usrbuf, rp->rio_bufptr, cnt);
    rp->rio_bufptr += cnt;
    rp->rio_cnt    -= cnt;
    return cnt;
}
static ssize_t rio_read ( struct rio_t * rp , char * usrbuf , size_t n ) { while ( rp -> rio_cnt <= 0 ) { rp -> rio_cnt = read ( rp -> rio_fd , rp -> rio_buf , sizeof ( rp -> rio_buf ) ) ; if ( rp -> rio_cnt < 0 ) { if ( errno != EINTR ) return -1 ; } else if ( rp -> rio_cnt == 0 ) { return 0 ; } else { rp -> rio_bufptr = rp -> rio_buf ; } } int cnt = rp -> rio_cnt < n ? rp -> rio_cnt : n ; memcpy ( usrbuf , rp -> rio_bufptr , cnt ) ; rp -> rio_bufptr += cnt ; rp -> rio_cnt -= cnt ; return cnt ; }
used by rio_readnb and rio_readlineb on the internal rio_buf
then store everything in usrbuf
used by rio_readnb and rio_readlineb on the internal rio_buf then store everything in usrbuf
// check if rio_buf is empty and try to fill it if it is // otherwise, do nothing // EOF