Browse code

Implement av_strerror().

Originally committed as revision 22684 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini authored on 2010/03/26 07:46:35
Showing 5 changed files
... ...
@@ -1074,6 +1074,7 @@ HAVE_LIST="
1074 1074
     soundcard_h
1075 1075
     poll_h
1076 1076
     setrlimit
1077
+    strerror_r
1077 1078
     struct_addrinfo
1078 1079
     struct_ipv6_mreq
1079 1080
     struct_sockaddr_in6
... ...
@@ -2531,6 +2532,7 @@ check_func  ${malloc_prefix}memalign            && enable memalign
2531 2531
 check_func  mkstemp
2532 2532
 check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
2533 2533
 check_func  setrlimit
2534
+check_func  strerror_r
2534 2535
 check_func_headers io.h setmode
2535 2536
 check_func_headers lzo/lzo1x.h lzo1x_999_compress
2536 2537
 check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
... ...
@@ -30,6 +30,7 @@ OBJS = adler32.o                                                        \
30 30
        base64.o                                                         \
31 31
        crc.o                                                            \
32 32
        des.o                                                            \
33
+       error.o                                                          \
33 34
        fifo.o                                                           \
34 35
        intfloat_readwrite.o                                             \
35 36
        lfg.o                                                            \
... ...
@@ -40,7 +40,7 @@
40 40
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
41 41
 
42 42
 #define LIBAVUTIL_VERSION_MAJOR 50
43
-#define LIBAVUTIL_VERSION_MINOR 12
43
+#define LIBAVUTIL_VERSION_MINOR 13
44 44
 #define LIBAVUTIL_VERSION_MICRO  0
45 45
 
46 46
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
47 47
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+/*
1
+ * This file is part of FFmpeg.
2
+ *
3
+ * FFmpeg is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * FFmpeg is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with FFmpeg; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#include "avutil.h"
19
+#include "avstring.h"
20
+
21
+int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
22
+{
23
+    int ret = 0;
24
+    const char *errstr = NULL;
25
+
26
+    switch (errnum) {
27
+    case AVERROR_EOF:               errstr = "End of file"; break;
28
+    case AVERROR_INVALIDDATA:       errstr = "Invalid data found when processing input"; break;
29
+    case AVERROR_NOTSUPP:           errstr = "Operation not supported"; break;
30
+    case AVERROR_NUMEXPECTED:       errstr = "Number syntax expected in filename"; break;
31
+    case AVERROR_PATCHWELCOME:      errstr = "Not yet implemented in FFmpeg, patches welcome"; break;
32
+    }
33
+
34
+    if (errstr) {
35
+        av_strlcpy(errbuf, errstr, errbuf_size);
36
+    } else {
37
+#if HAVE_STRERROR_R
38
+        ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
39
+#else
40
+        snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
41
+#endif
42
+    }
43
+
44
+    return ret;
45
+}
... ...
@@ -57,4 +57,14 @@
57 57
 #define AVERROR_NUMEXPECTED     (-MKTAG('N','U','E','X')) ///< Number syntax expected in filename
58 58
 #endif
59 59
 
60
+/**
61
+ * Puts a description of the AVERROR code errnum in errbuf.
62
+ * In case of failure the global variable errno is set to indicate the
63
+ * error.
64
+ *
65
+ * @param errbuf_size the size in bytes of errbuf
66
+ * @return 0 on success, a negative value otherwise
67
+ */
68
+int av_strerror(int errnum, char *errbuf, size_t errbuf_size);
69
+
60 70
 #endif /* AVUTIL_ERROR_H */