All pastes #561343 Raw Edit

Something

public text v1 · immutable
#561343 ·published 2007-06-12 12:35 UTC
rendered paste body
/* read_from_from:
    fd - file to read rom
    buffer - buffer to read into
    *length - maximum amount of data to read.
        On return *length becomes the amount of data actually read.
    Returns true if the file is finished, or error.
            false if there is still data to rbe read.
*/
static bool read_from_from(int fd, char *buffer, size_t *length)
{
    size_t ret, data_read = 0;
    while (*length > 0)
    {
        ret = read(fd, buffer, *length);
        if (ret < 0) /* error */
        {
            *length = 0;
            return true;
        }
        else if (ret == 0)
        {
            *length = data_read;
            return true; /* file finished */
        }
        else
        {
            data_read += ret;
            *length -= ret;
        }
    }
    *length = data_read;
    return false;
}