static int http_start_receive_data(HTTPContext *c)

{

    int fd;



    if (c->stream->feed_opened)

        return -1;



    /* Don't permit writing to this one */

    if (c->stream->readonly)

        return -1;



    /* open feed */

    fd = open(c->stream->feed_filename, O_RDWR);

    if (fd < 0) {

        http_log("Error opening feeder file: %s\n", strerror(errno));

        return -1;

    }

    c->feed_fd = fd;



    if (c->stream->truncate) {

        /* truncate feed file */

        ffm_write_write_index(c->feed_fd, FFM_PACKET_SIZE);

        ftruncate(c->feed_fd, FFM_PACKET_SIZE);

        http_log("Truncating feed file '%s'\n", c->stream->feed_filename);

    } else {

        if ((c->stream->feed_write_index = ffm_read_write_index(fd)) < 0) {

            http_log("Error reading write index from feed file: %s\n", strerror(errno));

            return -1;

        }

    }



    c->stream->feed_write_index = FFMAX(ffm_read_write_index(fd), FFM_PACKET_SIZE);

    c->stream->feed_size = lseek(fd, 0, SEEK_END);

    lseek(fd, 0, SEEK_SET);



    /* init buffer input */

    c->buffer_ptr = c->buffer;

    c->buffer_end = c->buffer + FFM_PACKET_SIZE;

    c->stream->feed_opened = 1;

    c->chunked_encoding = !!av_stristr(c->buffer, "Transfer-Encoding: chunked");

    return 0;

}

static int http_start_receive_data(HTTPContext *c)

{

    int fd;



    if (c->stream->feed_opened)

        return -1;



    

    if (c->stream->readonly)

        return -1;



    

    fd = open(c->stream->feed_filename, O_RDWR);

    if (fd < 0) {

        http_log("Error opening feeder file: %s\n", strerror(errno));

        return -1;

    }

    c->feed_fd = fd;



    if (c->stream->truncate) {

        

        ffm_write_write_index(c->feed_fd, FFM_PACKET_SIZE);

        ftruncate(c->feed_fd, FFM_PACKET_SIZE);

        http_log("Truncating feed file '%s'\n", c->stream->feed_filename);

    } else {

        if ((c->stream->feed_write_index = ffm_read_write_index(fd)) < 0) {

            http_log("Error reading write index from feed file: %s\n", strerror(errno));

            return -1;

        }

    }



    c->stream->feed_write_index = FFMAX(ffm_read_write_index(fd), FFM_PACKET_SIZE);

    c->stream->feed_size = lseek(fd, 0, SEEK_END);

    lseek(fd, 0, SEEK_SET);



    

    c->buffer_ptr = c->buffer;

    c->buffer_end = c->buffer + FFM_PACKET_SIZE;

    c->stream->feed_opened = 1;

    c->chunked_encoding = !!av_stristr(c->buffer, "Transfer-Encoding: chunked");

    return 0;

}

static int FUNC_0(HTTPContext *VAR_0)

{

    int VAR_1;



    if (VAR_0->stream->feed_opened)

        return -1;



    

    if (VAR_0->stream->readonly)

        return -1;



    

    VAR_1 = open(VAR_0->stream->feed_filename, O_RDWR);

    if (VAR_1 < 0) {

        http_log("Error opening feeder file: %s\n", strerror(errno));

        return -1;

    }

    VAR_0->feed_fd = VAR_1;



    if (VAR_0->stream->truncate) {

        

        ffm_write_write_index(VAR_0->feed_fd, FFM_PACKET_SIZE);

        ftruncate(VAR_0->feed_fd, FFM_PACKET_SIZE);

        http_log("Truncating feed file '%s'\n", VAR_0->stream->feed_filename);

    } else {

        if ((VAR_0->stream->feed_write_index = ffm_read_write_index(VAR_1)) < 0) {

            http_log("Error reading write index from feed file: %s\n", strerror(errno));

            return -1;

        }

    }



    VAR_0->stream->feed_write_index = FFMAX(ffm_read_write_index(VAR_1), FFM_PACKET_SIZE);

    VAR_0->stream->feed_size = lseek(VAR_1, 0, SEEK_END);

    lseek(VAR_1, 0, SEEK_SET);



    

    VAR_0->buffer_ptr = VAR_0->buffer;

    VAR_0->buffer_end = VAR_0->buffer + FFM_PACKET_SIZE;

    VAR_0->stream->feed_opened = 1;

    VAR_0->chunked_encoding = !!av_stristr(VAR_0->buffer, "Transfer-Encoding: chunked");

    return 0;

}

static int FUNC_0(HTTPContext *VAR_0)
{ int VAR_1; if (VAR_0->stream->feed_opened)
return -1; if (VAR_0->stream->readonly)
return -1; VAR_1 = open(VAR_0->stream->feed_filename, O_RDWR); if (VAR_1 < 0) { http_log("Error opening feeder file: %s\n", strerror(errno)); return -1; } VAR_0->feed_fd = VAR_1; if (VAR_0->stream->truncate) { ffm_write_write_index(VAR_0->feed_fd, FFM_PACKET_SIZE); ftruncate(VAR_0->feed_fd, FFM_PACKET_SIZE); http_log("Truncating feed file '%s'\n", VAR_0->stream->feed_filename); } else { if ((VAR_0->stream->feed_write_index = ffm_read_write_index(VAR_1)) < 0) { http_log("Error reading write index from feed file: %s\n", strerror(errno)); return -1; } } VAR_0->stream->feed_write_index = FFMAX(ffm_read_write_index(VAR_1), FFM_PACKET_SIZE); VAR_0->stream->feed_size = lseek(VAR_1, 0, SEEK_END); lseek(VAR_1, 0, SEEK_SET); VAR_0->buffer_ptr = VAR_0->buffer; VAR_0->buffer_end = VAR_0->buffer + FFM_PACKET_SIZE; VAR_0->stream->feed_opened = 1; VAR_0->chunked_encoding = !!av_stristr(VAR_0->buffer, "Transfer-Encoding: chunked"); return 0; }