diff mbox series

[FFmpeg-devel,18/60] avutil/file: use av_err2str to simplify code

Message ID D41CE2FHWEWO.181P7GYSH41C5@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,01/60] fftools/ffmpeg_opt: fix variable shadowing | expand

Commit Message

Marvin Scholz Sept. 8, 2024, 7:43 p.m. UTC
No need to explicitly specify the buffer here as it is only
ever passed to av_log, so av_err2str can be used.
---
 libavutil/file.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Anton Khirnov Sept. 11, 2024, 12:04 p.m. UTC | #1
Quoting Marvin Scholz (2024-09-08 21:43:39)
> No need to explicitly specify the buffer here as it is only
> ever passed to av_log, so av_err2str can be used.
> ---
>  libavutil/file.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)

Looks ok
diff mbox series

Patch

diff --git a/libavutil/file.c b/libavutil/file.c
index 2d1063b6a2..db8507286b 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -60,21 +60,18 @@  int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
     struct stat st;
     av_unused void *ptr;
     off_t off_size;
-    char errbuf[128];
     *bufptr = NULL;
     *size = 0;
 
     if (fd < 0) {
         err = AVERROR(errno);
-        av_strerror(err, errbuf, sizeof(errbuf));
-        av_log(&file_log_ctx, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, errbuf);
+        av_log(&file_log_ctx, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, av_err2str(err));
         return err;
     }
 
     if (fstat(fd, &st) < 0) {
         err = AVERROR(errno);
-        av_strerror(err, errbuf, sizeof(errbuf));
-        av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in fstat(): %s\n", errbuf);
+        av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in fstat(): %s\n", av_err2str(err));
         close(fd);
         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);
     if (ptr == MAP_FAILED) {
         err = AVERROR(errno);
-        av_strerror(err, errbuf, sizeof(errbuf));
-        av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
+        av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", av_err2str(err));
         close(fd);
         *size = 0;
         return err;