avutil/file: use av_err2str to simplify code

No need to explicitly specify the buffer here as it is only
ever passed to av_log, so av_err2str can be used.
This commit is contained in:
Marvin Scholz 2024-09-08 21:43:39 +02:00
parent 074bf9faf7
commit 5dfc547f25
1 changed files with 3 additions and 7 deletions

View File

@ -60,21 +60,18 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
struct stat st; struct stat st;
av_unused void *ptr; av_unused void *ptr;
off_t off_size; off_t off_size;
char errbuf[128];
*bufptr = NULL; *bufptr = NULL;
*size = 0; *size = 0;
if (fd < 0) { if (fd < 0) {
err = AVERROR(errno); err = AVERROR(errno);
av_strerror(err, errbuf, sizeof(errbuf)); av_log(&file_log_ctx, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, av_err2str(err));
av_log(&file_log_ctx, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, errbuf);
return err; return err;
} }
if (fstat(fd, &st) < 0) { if (fstat(fd, &st) < 0) {
err = AVERROR(errno); err = AVERROR(errno);
av_strerror(err, errbuf, sizeof(errbuf)); av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in fstat(): %s\n", av_err2str(err));
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in fstat(): %s\n", errbuf);
close(fd); close(fd);
return err; return err;
} }
@ -97,8 +94,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
ptr = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); ptr = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
if (ptr == MAP_FAILED) { if (ptr == MAP_FAILED) {
err = AVERROR(errno); err = AVERROR(errno);
av_strerror(err, errbuf, sizeof(errbuf)); av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", av_err2str(err));
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
close(fd); close(fd);
*size = 0; *size = 0;
return err; return err;