[vlc-devel] [PATCH 3/3] posix: use strerror_r() if strerror_l() is unimplemented

Sean McGovern gseanmcg at gmail.com
Sat Sep 12 19:23:07 CEST 2015


---
 src/posix/error.c |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/posix/error.c b/src/posix/error.c
index db51004..790e5bb 100644
--- a/src/posix/error.c
+++ b/src/posix/error.c
@@ -29,6 +29,23 @@
 
 #include <vlc_common.h>
 
+#ifndef HAVE_STRERROR_L
+static const char *vlc_strerror_r(int errnum)
+{
+#define BUF_LEN 256
+    char *buf = malloc(BUF_LEN);
+    if(unlikely(buf == NULL))
+        return buf;
+    
+    if(strerror_r(errnum, buf, BUF_LEN))
+    {
+        free(buf);
+        buf = NULL;
+    }
+    
+    return buf;
+}
+#else
 static const char *vlc_strerror_l(int errnum, const char *lname)
 {
     int saved_errno = errno;
@@ -53,6 +70,7 @@ static const char *vlc_strerror_l(int errnum, const char *lname)
     freelocale(loc);
     return buf;
 }
+#endif
 
 /**
  * Formats an error message in the current locale.
@@ -63,7 +81,11 @@ static const char *vlc_strerror_l(int errnum, const char *lname)
 const char *vlc_strerror(int errnum)
 {
     /* We cannot simply use strerror() here, since it is not thread-safe. */
+#ifndef HAVE_STRERROR_L
+    return vlc_strerror_r(errnum);
+#else
     return vlc_strerror_l(errnum, "");
+#endif
 }
 
 /**
@@ -74,5 +96,9 @@ const char *vlc_strerror(int errnum)
  */
 const char *vlc_strerror_c(int errnum)
 {
+#ifndef HAVE_STRERROR_L
+    return vlc_strerror_r(errnum);
+#else
     return vlc_strerror_l(errnum, "C");
+#endif
 }
-- 
1.7.9.2



More information about the vlc-devel mailing list