Also, drop the now unused cmdutils_read_file(). There is no reason to have two functions doing essentially the same thing.
Unified · Split
| @@ -1196,9 +1196,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) · 1195 unmodified lines | |||
| 1196 | } | 1196 | } |
| 1197 | ost->logfile = f; | 1197 | ost->logfile = f; |
| 1198 | } else { | 1198 | } else { |
| 1199 | char *logbuffer; | 1199 | char *logbuffer = read_file(logfilename); |
| 1200 | size_t logbuffer_size; | 1200 | |
| 1201 | if (cmdutils_read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { | 1201 | if (!logbuffer) { |
| 1202 | av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n", | 1202 | av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n", |
| 1203 | logfilename); | 1203 | logfilename); |
| 1204 | exit_program(1); | 1204 | exit_program(1); |
| @@ -1396,61 +1396,6 @@ int read_yesno(void) · 1395 unmodified lines | |||
| 1396 | return yesno; | 1396 | return yesno; |
| 1397 | } | 1397 | } |
| 1398 | 1398 | ||
| 1399 | int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) | ||
| 1400 | { | ||
| 1401 | int ret; | ||
| 1402 | FILE *f = fopen(filename, "rb"); | ||
| 1403 | |||
| 1404 | if (!f) { | ||
| 1405 | av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, | ||
| 1406 | strerror(errno)); | ||
| 1407 | return AVERROR(errno); | ||
| 1408 | } | ||
| 1409 | |||
| 1410 | ret = fseek(f, 0, SEEK_END); | ||
| 1411 | if (ret == -1) { | ||
| 1412 | ret = AVERROR(errno); | ||
| 1413 | goto out; | ||
| 1414 | } | ||
| 1415 | |||
| 1416 | ret = ftell(f); | ||
| 1417 | if (ret < 0) { | ||
| 1418 | ret = AVERROR(errno); | ||
| 1419 | goto out; | ||
| 1420 | } | ||
| 1421 | *size = ret; | ||
| 1422 | |||
| 1423 | ret = fseek(f, 0, SEEK_SET); | ||
| 1424 | if (ret == -1) { | ||
| 1425 | ret = AVERROR(errno); | ||
| 1426 | goto out; | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | *bufptr = av_malloc(*size + 1); | ||
| 1430 | if (!*bufptr) { | ||
| 1431 | av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n"); | ||
| 1432 | ret = AVERROR(ENOMEM); | ||
| 1433 | goto out; | ||
| 1434 | } | ||
| 1435 | ret = fread(*bufptr, 1, *size, f); | ||
| 1436 | if (ret < *size) { | ||
| 1437 | av_free(*bufptr); | ||
| 1438 | if (ferror(f)) { | ||
| 1439 | av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n", | ||
| 1440 | filename, strerror(errno)); | ||
| 1441 | ret = AVERROR(errno); | ||
| 1442 | } else | ||
| 1443 | ret = AVERROR_EOF; | ||
| 1444 | } else { | ||
| 1445 | ret = 0; | ||
| 1446 | (*bufptr)[(*size)++] = '\0'; | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | out: | ||
| 1450 | fclose(f); | ||
| 1451 | return ret; | ||
| 1452 | } | ||
| 1453 | |||
| 1454 | void init_pts_correction(PtsCorrectionContext *ctx) | 1399 | void init_pts_correction(PtsCorrectionContext *ctx) |
| 1455 | { | 1400 | { |
| 1456 | ctx->num_faulty_pts = ctx->num_faulty_dts = 0; | 1401 | ctx->num_faulty_pts = ctx->num_faulty_dts = 0; |
| @@ -460,18 +460,6 @@ int show_sample_fmts(void *optctx, const char *opt, const char *arg); · 459 unmodified lines | |||
| 460 | */ | 460 | */ |
| 461 | int read_yesno(void); | 461 | int read_yesno(void); |
| 462 | 462 | ||
| 463 | /** | ||
| 464 | * Read the file with name filename, and put its content in a newly | ||
| 465 | * allocated 0-terminated buffer. | ||
| 466 | * | ||
| 467 | * @param filename file to read from | ||
| 468 | * @param bufptr location where pointer to buffer is returned | ||
| 469 | * @param size location where size of buffer is returned | ||
| 470 | * @return 0 in case of success, a negative value corresponding to an | ||
| 471 | * AVERROR error code in case of failure. | ||
| 472 | */ | ||
| 473 | int cmdutils_read_file(const char *filename, char **bufptr, size_t *size); | ||
| 474 | |||
| 475 | typedef struct PtsCorrectionContext { | 463 | typedef struct PtsCorrectionContext { |
| 476 | int64_t num_faulty_pts; /// Number of incorrect PTS values so far | 464 | int64_t num_faulty_pts; /// Number of incorrect PTS values so far |
| 477 | int64_t num_faulty_dts; /// Number of incorrect DTS values so far | 465 | int64_t num_faulty_dts; /// Number of incorrect DTS values so far |