yading@11: /* yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #undef _GNU_SOURCE yading@11: #include "avutil.h" yading@11: #include "avstring.h" yading@11: #include "common.h" yading@11: yading@11: struct error_entry { yading@11: int num; yading@11: const char *tag; yading@11: const char *str; yading@11: }; yading@11: yading@11: #define ERROR_TAG(tag) AVERROR_##tag, #tag yading@11: static const struct error_entry error_entries[] = { yading@11: { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" }, yading@11: { ERROR_TAG(BUG), "Internal bug, should not have happened" }, yading@11: { ERROR_TAG(BUG2), "Internal bug, should not have happened" }, yading@11: { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" }, yading@11: { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" }, yading@11: { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" }, yading@11: { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" }, yading@11: { ERROR_TAG(EOF), "End of file" }, yading@11: { ERROR_TAG(EXIT), "Immediate exit requested" }, yading@11: { ERROR_TAG(EXTERNAL), "Generic error in an external library" }, yading@11: { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" }, yading@11: { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" }, yading@11: { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" }, yading@11: { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" }, yading@11: { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" }, yading@11: { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" }, yading@11: { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" }, yading@11: { ERROR_TAG(UNKNOWN), "Unknown error occurred" }, yading@11: { ERROR_TAG(EXPERIMENTAL), "Experimental feature" }, yading@11: }; yading@11: yading@11: int av_strerror(int errnum, char *errbuf, size_t errbuf_size) yading@11: { yading@11: int ret = 0, i; yading@11: const struct error_entry *entry = NULL; yading@11: yading@11: for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) { yading@11: if (errnum == error_entries[i].num) { yading@11: entry = &error_entries[i]; yading@11: break; yading@11: } yading@11: } yading@11: if (entry) { yading@11: av_strlcpy(errbuf, entry->str, errbuf_size); yading@11: } else { yading@11: #if HAVE_STRERROR_R yading@11: ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size)); yading@11: #else yading@11: ret = -1; yading@11: #endif yading@11: if (ret < 0) yading@11: snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum); yading@11: } yading@11: yading@11: return ret; yading@11: } yading@11: yading@11: #ifdef TEST yading@11: yading@11: #undef printf yading@11: yading@11: int main(void) yading@11: { yading@11: int i; yading@11: yading@11: for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) { yading@11: const struct error_entry *entry = &error_entries[i]; yading@11: printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag); yading@11: } yading@11: yading@11: for (i = 0; i < 256; i++) { yading@11: printf("%d: %s\n", -i, av_err2str(-i)); yading@11: } yading@11: yading@11: return 0; yading@11: } yading@11: yading@11: #endif /* TEST */