[FFmpeg-devel] [PATCH] Implement read_file() cmdutils.c option

Stefano Sabatini stefano.sabatini-lala
Thu Apr 1 01:03:32 CEST 2010


On date Wednesday 2010-03-31 23:32:09 +0200, Michael Niedermayer encoded:
> On Wed, Mar 31, 2010 at 10:06:33PM +0200, Stefano Sabatini wrote:
[...]
> > Subject: [PATCH 1/2] Implement cmdutils.c:read_file(), and use it in ffmpeg.c for reading
> >  the second pass encoding log file.
> > 
> > ---
> >  cmdutils.c |   23 +++++++++++++++++++++++
> >  cmdutils.h |   11 +++++++++++
> >  ffmpeg.c   |   21 ++++-----------------
> >  3 files changed, 38 insertions(+), 17 deletions(-)
> > 
> > diff --git a/cmdutils.c b/cmdutils.c
> > index c2c44c6..8c5561c 100644
> > --- a/cmdutils.c
> > +++ b/cmdutils.c
> > @@ -639,3 +639,26 @@ int read_yesno(void)
> >  
> >      return yesno;
> >  }
> > +
> > +int read_file(const char *filename, char **bufptr, size_t *size)
> > +{
> > +    FILE *f = fopen(filename, "r");
> > +
> > +    if (!f) {
> > +        fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno));
> > +        return AVERROR(errno);
> > +    }
> > +    fseek(f, 0, SEEK_END);
> > +    *size = ftell(f);
> > +    fseek(f, 0, SEEK_SET);
> > +    *bufptr = av_malloc(*size + 1);
> > +    if (!*bufptr) {
> > +        fprintf(stderr, "Could not allocate file buffer\n");
> > +        return AVERROR(ENOMEM);
> > +    }
> 
> missing fclose()

Ouch, fixed, regards.
-- 
FFmpeg = Formidable Fierce Mastering Peaceful Earthshaking Game



More information about the ffmpeg-devel mailing list