FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/error.c
Date: 2024-02-29 09:57:37
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 1 1 100.0%
Branches: 8 8 100.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #undef _GNU_SOURCE
20 #define _XOPEN_SOURCE 600 /* XSI-compliant version of strerror_r */
21 #include <stdio.h>
22 #include <string.h>
23 #include "config.h"
24 #include "avstring.h"
25 #include "error.h"
26 #include "macros.h"
27
28 struct error_entry {
29 int num;
30 const char *tag;
31 const char *str;
32 };
33
34 #define ERROR_TAG(tag) AVERROR_##tag, #tag
35 #define EERROR_TAG(tag) AVERROR(tag), #tag
36 #define AVERROR_INPUT_AND_OUTPUT_CHANGED (AVERROR_INPUT_CHANGED | AVERROR_OUTPUT_CHANGED)
37 static const struct error_entry error_entries[] = {
38 { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" },
39 { ERROR_TAG(BUG), "Internal bug, should not have happened" },
40 { ERROR_TAG(BUG2), "Internal bug, should not have happened" },
41 { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" },
42 { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" },
43 { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" },
44 { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" },
45 { ERROR_TAG(EOF), "End of file" },
46 { ERROR_TAG(EXIT), "Immediate exit requested" },
47 { ERROR_TAG(EXTERNAL), "Generic error in an external library" },
48 { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" },
49 { ERROR_TAG(INPUT_CHANGED), "Input changed" },
50 { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" },
51 { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" },
52 { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" },
53 { ERROR_TAG(OUTPUT_CHANGED), "Output changed" },
54 { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" },
55 { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" },
56 { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" },
57 { ERROR_TAG(UNKNOWN), "Unknown error occurred" },
58 { ERROR_TAG(EXPERIMENTAL), "Experimental feature" },
59 { ERROR_TAG(INPUT_AND_OUTPUT_CHANGED), "Input and output changed" },
60 { ERROR_TAG(HTTP_BAD_REQUEST), "Server returned 400 Bad Request" },
61 { ERROR_TAG(HTTP_UNAUTHORIZED), "Server returned 401 Unauthorized (authorization failed)" },
62 { ERROR_TAG(HTTP_FORBIDDEN), "Server returned 403 Forbidden (access denied)" },
63 { ERROR_TAG(HTTP_NOT_FOUND), "Server returned 404 Not Found" },
64 { ERROR_TAG(HTTP_OTHER_4XX), "Server returned 4XX Client Error, but not one of 40{0,1,3,4}" },
65 { ERROR_TAG(HTTP_SERVER_ERROR), "Server returned 5XX Server Error reply" },
66 #if !HAVE_STRERROR_R
67 { EERROR_TAG(E2BIG), "Argument list too long" },
68 { EERROR_TAG(EACCES), "Permission denied" },
69 { EERROR_TAG(EAGAIN), "Resource temporarily unavailable" },
70 { EERROR_TAG(EBADF), "Bad file descriptor" },
71 { EERROR_TAG(EBUSY), "Device or resource busy" },
72 { EERROR_TAG(ECHILD), "No child processes" },
73 { EERROR_TAG(EDEADLK), "Resource deadlock avoided" },
74 { EERROR_TAG(EDOM), "Numerical argument out of domain" },
75 { EERROR_TAG(EEXIST), "File exists" },
76 { EERROR_TAG(EFAULT), "Bad address" },
77 { EERROR_TAG(EFBIG), "File too large" },
78 { EERROR_TAG(EILSEQ), "Illegal byte sequence" },
79 { EERROR_TAG(EINTR), "Interrupted system call" },
80 { EERROR_TAG(EINVAL), "Invalid argument" },
81 { EERROR_TAG(EIO), "I/O error" },
82 { EERROR_TAG(EISDIR), "Is a directory" },
83 { EERROR_TAG(EMFILE), "Too many open files" },
84 { EERROR_TAG(EMLINK), "Too many links" },
85 { EERROR_TAG(ENAMETOOLONG), "File name too long" },
86 { EERROR_TAG(ENFILE), "Too many open files in system" },
87 { EERROR_TAG(ENODEV), "No such device" },
88 { EERROR_TAG(ENOENT), "No such file or directory" },
89 { EERROR_TAG(ENOEXEC), "Exec format error" },
90 { EERROR_TAG(ENOLCK), "No locks available" },
91 { EERROR_TAG(ENOMEM), "Cannot allocate memory" },
92 { EERROR_TAG(ENOSPC), "No space left on device" },
93 { EERROR_TAG(ENOSYS), "Function not implemented" },
94 { EERROR_TAG(ENOTDIR), "Not a directory" },
95 { EERROR_TAG(ENOTEMPTY), "Directory not empty" },
96 { EERROR_TAG(ENOTTY), "Inappropriate I/O control operation" },
97 { EERROR_TAG(ENXIO), "No such device or address" },
98 { EERROR_TAG(EPERM), "Operation not permitted" },
99 { EERROR_TAG(EPIPE), "Broken pipe" },
100 { EERROR_TAG(ERANGE), "Result too large" },
101 { EERROR_TAG(EROFS), "Read-only file system" },
102 { EERROR_TAG(ESPIPE), "Illegal seek" },
103 { EERROR_TAG(ESRCH), "No such process" },
104 { EERROR_TAG(EXDEV), "Cross-device link" },
105 #endif
106 };
107
108 616 int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
109 {
110 616 int ret = 0, i;
111 616 const struct error_entry *entry = NULL;
112
113
2/2
✓ Branch 0 taken 10562 times.
✓ Branch 1 taken 164 times.
10726 for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
114
2/2
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 10110 times.
10562 if (errnum == error_entries[i].num) {
115 452 entry = &error_entries[i];
116 452 break;
117 }
118 }
119
2/2
✓ Branch 0 taken 452 times.
✓ Branch 1 taken 164 times.
616 if (entry) {
120 452 av_strlcpy(errbuf, entry->str, errbuf_size);
121 } else {
122 #if HAVE_STRERROR_R
123 164 ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
124 #else
125 ret = -1;
126 #endif
127
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 162 times.
164 if (ret < 0)
128 2 snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
129 }
130
131 616 return ret;
132 }
133