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