[PATCH 7/8] Implement av_strerror().
Stefano Sabatini
stefano.sabatini-lala
Sun Mar 14 01:06:46 CET 2010
---
configure | 2 +
libavutil/Makefile | 1 +
libavutil/avutil.h | 2 +-
libavutil/error.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
libavutil/error.h | 9 ++++++
5 files changed, 92 insertions(+), 1 deletions(-)
create mode 100644 libavutil/error.c
diff --git a/configure b/configure
index 60834ca..459e990 100755
--- a/configure
+++ b/configure
@@ -1071,6 +1071,7 @@ HAVE_LIST="
soundcard_h
poll_h
setrlimit
+ strerror_r
struct_addrinfo
struct_ipv6_mreq
struct_sockaddr_in6
@@ -2525,6 +2526,7 @@ check_func ${malloc_prefix}memalign && enable memalign
check_func mkstemp
check_func ${malloc_prefix}posix_memalign && enable posix_memalign
check_func setrlimit
+check_func strerror_r
check_func_headers io.h setmode
check_func_headers lzo/lzo1x.h lzo1x_999_compress
check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 5b6cd0e..79506c0 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -30,6 +30,7 @@ OBJS = adler32.o \
base64.o \
crc.o \
des.o \
+ error.o \
fifo.o \
intfloat_readwrite.o \
lfg.o \
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 47630a7..968787c 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 50
-#define LIBAVUTIL_VERSION_MINOR 12
+#define LIBAVUTIL_VERSION_MINOR 13
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/error.c b/libavutil/error.c
new file mode 100644
index 0000000..918c989
--- /dev/null
+++ b/libavutil/error.c
@@ -0,0 +1,79 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avutil.h"
+#include "avstring.h"
+
+int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
+{
+ int ret = 0;
+ const char *errstr = NULL;
+ *errbuf = 0;
+
+ switch (errnum) {
+ case AVERROR_EOF: errstr = "End of file"; break;
+ case AVERROR_INVALIDDATA: errstr = "Invalid data found"; break;
+ case AVERROR_NOFMT: errstr = "Unknown format"; break;
+ case AVERROR_NOTSUPP: errstr = "Operation not supported"; break;
+ case AVERROR_NUMEXPECTED: errstr = "Number syntax expected in filename"; break;
+ case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break;
+ }
+
+ if (errstr) {
+ av_strlcpy(errbuf, errstr, errbuf_size);
+ } else {
+#if HAVE_STRERROR_R
+ ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
+#else
+ snprintf(errbuf, errbuf_size, "Error number %d", errnum);
+#endif
+ }
+
+ return ret;
+}
+
+#if TEST
+
+#undef printf
+
+int main(void)
+{
+ int i, ret;
+ char errbuf[256];
+
+ for (i = 0; i > -256; i--) {
+ ret = av_strerror(i, errbuf, sizeof(errbuf));
+ printf("%d: %s ret:%d\n", i, errbuf, ret);
+ }
+
+#define PRINTERR(ERR) \
+ av_strerror(AVERROR_##ERR, errbuf, sizeof(errbuf)); \
+ printf("%d[%s]: %s\n", AVERROR_##ERR, #ERR, errbuf)
+
+ PRINTERR(IO);
+ PRINTERR(NOENT);
+ PRINTERR(NOMEM);
+ PRINTERR(EOF);
+ PRINTERR(INVALIDDATA);
+ PRINTERR(NOFMT);
+ PRINTERR(NOTSUPP);
+ PRINTERR(NUMEXPECTED);
+ PRINTERR(PATCHWELCOME);
+}
+
+#endif
diff --git a/libavutil/error.h b/libavutil/error.h
index 060defc..252921f 100644
--- a/libavutil/error.h
+++ b/libavutil/error.h
@@ -56,4 +56,13 @@
#define AVERROR_NUMEXPECTED (-MKTAG('N','U','E','X')) /**< Number syntax expected in filename. */
#endif
+/**
+ * Puts a description of the AVERROR code errnum in errbuf.
+ * In case of failure errno is set to indicate the error.
+ *
+ * @param errbuf_size the size in bytes of errbuf
+ * @return 0 on success, -1 otherwise
+ */
+int av_strerror(int errnum, char *errbuf, size_t errbuf_size);
+
#endif /* AVUTIL_ERROR_H */
--
1.6.6.1
--U+BazGySraz5kW0T
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="error-test.out"
0: Success ret:0
-1: Operation not permitted ret:0
-2: No such file or directory ret:0
-3: No such process ret:0
-4: Interrupted system call ret:0
-5: Input/output error ret:0
-6: No such device or address ret:0
-7: Argument list too long ret:0
-8: Exec format error ret:0
-9: Bad file descriptor ret:0
-10: No child processes ret:0
-11: Resource temporarily unavailable ret:0
-12: Cannot allocate memory ret:0
-13: Permission denied ret:0
-14: Bad address ret:0
-15: Block device required ret:0
-16: Device or resource busy ret:0
-17: File exists ret:0
-18: Invalid cross-device link ret:0
-19: No such device ret:0
-20: Not a directory ret:0
-21: Is a directory ret:0
-22: Invalid data found ret:0
-23: Too many open files in system ret:0
-24: Too many open files ret:0
-25: Inappropriate ioctl for device ret:0
-26: Text file busy ret:0
-27: File too large ret:0
-28: No space left on device ret:0
-29: Illegal seek ret:0
-30: Read-only file system ret:0
-31: Too many links ret:0
-32: End of file ret:0
-33: Number syntax expected in filename ret:0
-34: Numerical result out of range ret:0
-35: Resource deadlock avoided ret:0
-36: File name too long ret:0
-37: No locks available ret:0
-38: Operation not supported ret:0
-39: Directory not empty ret:0
-40: Too many levels of symbolic links ret:0
-41: ret:-1
-42: No message of desired type ret:0
-43: Identifier removed ret:0
-44: Channel number out of range ret:0
-45: Level 2 not synchronized ret:0
-46: Level 3 halted ret:0
-47: Level 3 reset ret:0
-48: Link number out of range ret:0
-49: Protocol driver not attached ret:0
-50: No CSI structure available ret:0
-51: Level 2 halted ret:0
-52: Invalid exchange ret:0
-53: Invalid request descriptor ret:0
-54: Exchange full ret:0
-55: No anode ret:0
-56: Invalid request code ret:0
-57: Invalid slot ret:0
-58: ret:-1
-59: Bad font file format ret:0
-60: Device not a stream ret:0
-61: No data available ret:0
-62: Timer expired ret:0
-63: Out of streams resources ret:0
-64: Machine is not on the network ret:0
-65: Package not installed ret:0
-66: Object is remote ret:0
-67: Link has been severed ret:0
-68: Advertise error ret:0
-69: Srmount error ret:0
-70: Communication error on send ret:0
-71: Protocol error ret:0
-72: Multihop attempted ret:0
-73: RFS specific error ret:0
-74: Bad message ret:0
-75: Value too large for defined data type ret:0
-76: Name not unique on network ret:0
-77: File descriptor in bad state ret:0
-78: Remote address changed ret:0
-79: Can not access a needed shared library ret:0
-80: Accessing a corrupted shared library ret:0
-81: .lib section in a.out corrupted ret:0
-82: Attempting to link in too many shared libraries ret:0
-83: Cannot exec a shared library directly ret:0
-84: Unknown format ret:0
-85: Interrupted system call should be restarted ret:0
-86: Streams pipe error ret:0
-87: Too many users ret:0
-88: Socket operation on non-socket ret:0
-89: Destination address required ret:0
-90: Message too long ret:0
-91: Protocol wrong type for socket ret:0
-92: Protocol not available ret:0
-93: Protocol not supported ret:0
-94: Socket type not supported ret:0
-95: Operation not supported ret:0
-96: Protocol family not supported ret:0
-97: Address family not supported by protocol ret:0
-98: Address already in use ret:0
-99: Cannot assign requested address ret:0
-100: Network is down ret:0
-101: Network is unreachable ret:0
-102: Network dropped connection on reset ret:0
-103: Software caused connection abort ret:0
-104: Connection reset by peer ret:0
-105: No buffer space available ret:0
-106: Transport endpoint is already connected ret:0
-107: Transport endpoint is not connected ret:0
-108: Cannot send after transport endpoint shutdown ret:0
-109: Too many references: cannot splice ret:0
-110: Connection timed out ret:0
-111: Connection refused ret:0
-112: Host is down ret:0
-113: No route to host ret:0
-114: Operation already in progress ret:0
-115: Operation now in progress ret:0
-116: Stale NFS file handle ret:0
-117: Structure needs cleaning ret:0
-118: Not a XENIX named type file ret:0
-119: No XENIX semaphores available ret:0
-120: Is a named type file ret:0
-121: Remote I/O error ret:0
-122: Disk quota exceeded ret:0
-123: No medium found ret:0
-124: Wrong medium type ret:0
-125: Operation canceled ret:0
-126: Required key not available ret:0
-127: Key has expired ret:0
-128: Key has been revoked ret:0
-129: Key was rejected by service ret:0
-130: Owner died ret:0
-131: State not recoverable ret:0
-132: ret:-1
-133: ret:-1
-134: ret:-1
-135: ret:-1
-136: ret:-1
-137: ret:-1
-138: ret:-1
-139: ret:-1
-140: ret:-1
-141: ret:-1
-142: ret:-1
-143: ret:-1
-144: ret:-1
-145: ret:-1
-146: ret:-1
-147: ret:-1
-148: ret:-1
-149: ret:-1
-150: ret:-1
-151: ret:-1
-152: ret:-1
-153: ret:-1
-154: ret:-1
-155: ret:-1
-156: ret:-1
-157: ret:-1
-158: ret:-1
-159: ret:-1
-160: ret:-1
-161: ret:-1
-162: ret:-1
-163: ret:-1
-164: ret:-1
-165: ret:-1
-166: ret:-1
-167: ret:-1
-168: ret:-1
-169: ret:-1
-170: ret:-1
-171: ret:-1
-172: ret:-1
-173: ret:-1
-174: ret:-1
-175: ret:-1
-176: ret:-1
-177: ret:-1
-178: ret:-1
-179: ret:-1
-180: ret:-1
-181: ret:-1
-182: ret:-1
-183: ret:-1
-184: ret:-1
-185: ret:-1
-186: ret:-1
-187: ret:-1
-188: ret:-1
-189: ret:-1
-190: ret:-1
-191: ret:-1
-192: ret:-1
-193: ret:-1
-194: ret:-1
-195: ret:-1
-196: ret:-1
-197: ret:-1
-198: ret:-1
-199: ret:-1
-200: ret:-1
-201: ret:-1
-202: ret:-1
-203: ret:-1
-204: ret:-1
-205: ret:-1
-206: ret:-1
-207: ret:-1
-208: ret:-1
-209: ret:-1
-210: ret:-1
-211: ret:-1
-212: ret:-1
-213: ret:-1
-214: ret:-1
-215: ret:-1
-216: ret:-1
-217: ret:-1
-218: ret:-1
-219: ret:-1
-220: ret:-1
-221: ret:-1
-222: ret:-1
-223: ret:-1
-224: ret:-1
-225: ret:-1
-226: ret:-1
-227: ret:-1
-228: ret:-1
-229: ret:-1
-230: ret:-1
-231: ret:-1
-232: ret:-1
-233: ret:-1
-234: ret:-1
-235: ret:-1
-236: ret:-1
-237: ret:-1
-238: ret:-1
-239: ret:-1
-240: ret:-1
-241: ret:-1
-242: ret:-1
-243: ret:-1
-244: ret:-1
-245: ret:-1
-246: ret:-1
-247: ret:-1
-248: ret:-1
-249: ret:-1
-250: ret:-1
-251: ret:-1
-252: ret:-1
-253: ret:-1
-254: ret:-1
-255: ret:-1
-5[IO]: Input/output error
-2[NOENT]: No such file or directory
-12[NOMEM]: Cannot allocate memory
-32[EOF]: End of file
-22[INVALIDDATA]: Invalid data found
-84[NOFMT]: Unknown format
-38[NOTSUPP]: Operation not supported
-33[NUMEXPECTED]: Number syntax expected in filename
-1163346256[PATCHWELCOME]: Not yet implemented in FFmpeg, patches welcome
--U+BazGySraz5kW0T--
More information about the ffmpeg-devel
mailing list