diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-04-01 22:34:22 +0000 |
---|---|---|
committer | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2010-04-01 22:34:22 +0000 |
commit | 458b062d61a92d725cde9363941747a1c6d1e575 (patch) | |
tree | ee10867788ffec5cb35c5bcc4a52b29e182a3005 /cmdutils.c | |
parent | 339f5f39573dcdcb16f2dba563f784340a61b189 (diff) | |
download | ffmpeg-458b062d61a92d725cde9363941747a1c6d1e575.tar.gz |
Implement cmdutils.c:read_file(), and use it in ffmpeg.c for reading
the second pass encoding log file.
Originally committed as revision 22769 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'cmdutils.c')
-rw-r--r-- | cmdutils.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cmdutils.c b/cmdutils.c index c2c44c67ff..7e652a1e7f 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -639,3 +639,27 @@ 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"); + fclose(f); + return AVERROR(ENOMEM); + } + fread(*bufptr, 1, *size, f); + (*bufptr)[*size++] = '\0'; + + fclose(f); + return 0; +} |