url_fseek(pb, 0, SEEK_SET);
if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) { url_fclose(pb); if (url_fopen(pb, filename, URL_RDONLY) < 0) { err = AVERROR_IO; goto fail; } }
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,                        AVInputFormat *fmt,                       int buf_size,                       AVFormatParameters *ap){    int err, must_open_file, file_opened;    uint8_t buf[PROBE_BUF_SIZE];    AVProbeData probe_data, *pd = &probe_data;    ByteIOContext pb1, *pb = &pb1;        file_opened = 0;    pd->filename = "";    if (filename)        pd->filename = filename;    pd->buf = buf;    pd->buf_size = 0;    if (!fmt) {        /* guess format if no file can be opened  */        fmt = av_probe_input_format(pd, 0);    }    /* do not open file if the format does not need it. XXX: specific       hack needed to handle RTSP/TCP */    must_open_file = 1;    if (fmt && (fmt->flags & AVFMT_NOFILE)) {        must_open_file = 0;    }    if (!fmt || must_open_file) {        /* if no file needed do not try to open one */        if (url_fopen(pb, filename, URL_RDONLY) < 0) {            err = AVERROR_IO;            goto fail;        }        file_opened = 1;        if (buf_size > 0) {            url_setbufsize(pb, buf_size);        }        if (!fmt) {            /* read probe data */            pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);            url_fseek(pb, 0, SEEK_SET);        }    }        /* guess file format */    if (!fmt) {        fmt = av_probe_input_format(pd, 1);    }    /* if still no format found, error */    if (!fmt) {        err = AVERROR_NOFMT;        goto fail;    }            /* XXX: suppress this hack for redirectors */#ifdef CONFIG_NETWORK    if (fmt == &redir_demux) {        err = redir_open(ic_ptr, pb);        url_fclose(pb);        return err;    }#endif    /* check filename in case of an image number is expected */    if (fmt->flags & AVFMT_NEEDNUMBER) {        if (filename_number_test(filename) < 0) {             err = AVERROR_NUMEXPECTED;            goto fail;        }    }    err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);    if (err)        goto fail;    return 0; fail:    if (file_opened)        url_fclose(pb);    *ic_ptr = NULL;    return err;    }