This provides more verbose error messages than the strerror
fallback in cmdutils.c (which might not necessarily be a good thing),
but it also is able to handle network error codes.
---
 libavutil/error.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavutil/error.c b/libavutil/error.c
index 21b6876..d7f299c 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -18,6 +18,9 @@
 
 #include "avutil.h"
 #include "avstring.h"
+#ifdef _WIN32
+#include <windows.h>
+#endif
 
 int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
 {
@@ -45,7 +48,15 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
     if (errstr) {
         av_strlcpy(errbuf, errstr, errbuf_size);
     } else {
-#if HAVE_STRERROR_R
+#ifdef _WIN32
+        if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+                           FORMAT_MESSAGE_IGNORE_INSERTS |
+                           FORMAT_MESSAGE_MAX_WIDTH_MASK,
+                           NULL, AVUNERROR(errnum),
+                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errbuf,
+                           errbuf_size, NULL) <= 0)
+            ret = -1;
+#elif defined(HAVE_STRERROR_R)
         ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
 #else
         ret = -1;
-- 
1.7.9.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to