int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)

{

    int len;



    if (size < 0)

        return -1;



    if (s->read_packet && s->write_flag) {

        len = s->read_packet(s->opaque, buf, size);

        if (len > 0)

            s->pos += len;

        return len;

    }



    len = s->buf_end - s->buf_ptr;

    if (len == 0) {

        /* Reset the buf_end pointer to the start of the buffer, to make sure

         * the fill_buffer call tries to read as much data as fits into the

         * full buffer, instead of just what space is left after buf_end.

         * This avoids returning partial packets at the end of the buffer,

         * for packet based inputs.

         */

        s->buf_end = s->buf_ptr = s->buffer;

        fill_buffer(s);

        len = s->buf_end - s->buf_ptr;

    }

    if (len > size)

        len = size;

    memcpy(buf, s->buf_ptr, len);

    s->buf_ptr += len;

    if (!len) {

        if (s->error)      return s->error;

        if (avio_feof(s))  return AVERROR_EOF;

    }

    return len;

}

int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)

{

    int len;



    if (size < 0)

        return -1;



    if (s->read_packet && s->write_flag) {

        len = s->read_packet(s->opaque, buf, size);

        if (len > 0)

            s->pos += len;

        return len;

    }



    len = s->buf_end - s->buf_ptr;

    if (len == 0) {

        











        s->buf_end = s->buf_ptr = s->buffer;

        fill_buffer(s);

        len = s->buf_end - s->buf_ptr;

    }

    if (len > size)

        len = size;

    memcpy(buf, s->buf_ptr, len);

    s->buf_ptr += len;

    if (!len) {

        if (s->error)      return s->error;

        if (avio_feof(s))  return AVERROR_EOF;

    }

    return len;

}

int FUNC_0(AVIOContext *VAR_0, unsigned char *VAR_1, int VAR_2)

{

    int VAR_3;



    if (VAR_2 < 0)

        return -1;



    if (VAR_0->read_packet && VAR_0->write_flag) {

        VAR_3 = VAR_0->read_packet(VAR_0->opaque, VAR_1, VAR_2);

        if (VAR_3 > 0)

            VAR_0->pos += VAR_3;

        return VAR_3;

    }



    VAR_3 = VAR_0->buf_end - VAR_0->buf_ptr;

    if (VAR_3 == 0) {

        











        VAR_0->buf_end = VAR_0->buf_ptr = VAR_0->buffer;

        fill_buffer(VAR_0);

        VAR_3 = VAR_0->buf_end - VAR_0->buf_ptr;

    }

    if (VAR_3 > VAR_2)

        VAR_3 = VAR_2;

    memcpy(VAR_1, VAR_0->buf_ptr, VAR_3);

    VAR_0->buf_ptr += VAR_3;

    if (!VAR_3) {

        if (VAR_0->error)      return VAR_0->error;

        if (avio_feof(VAR_0))  return AVERROR_EOF;

    }

    return VAR_3;

}

int FUNC_0(AVIOContext *VAR_0, unsigned char *VAR_1, int VAR_2)
{ int VAR_3; if (VAR_2 < 0)
return -1; if (VAR_0->read_packet && VAR_0->write_flag) { VAR_3 = VAR_0->read_packet(VAR_0->opaque, VAR_1, VAR_2); if (VAR_3 > 0)
VAR_0->pos += VAR_3; return VAR_3; } VAR_3 = VAR_0->buf_end - VAR_0->buf_ptr; if (VAR_3 == 0) { VAR_0->buf_end = VAR_0->buf_ptr = VAR_0->buffer; fill_buffer(VAR_0); VAR_3 = VAR_0->buf_end - VAR_0->buf_ptr; } if (VAR_3 > VAR_2)
VAR_3 = VAR_2; memcpy(VAR_1, VAR_0->buf_ptr, VAR_3); VAR_0->buf_ptr += VAR_3; if (!VAR_3) { if (VAR_0->error)      return VAR_0->error; if (avio_feof(VAR_0))  return AVERROR_EOF; } return VAR_3; }