mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-12 18:10:13 +01:00
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
This commit is contained in:
24
cmdutils.c
24
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user