]> git.sesse.net Git - vlc/commitdiff
use strerror_r() which is guaranteed to be thread safe, using the GNU prototype only...
authorRafaël Carré <funman@videolan.org>
Mon, 25 Feb 2008 13:38:26 +0000 (13:38 +0000)
committerRafaël Carré <funman@videolan.org>
Mon, 25 Feb 2008 13:38:26 +0000 (13:38 +0000)
src/misc/threads.c

index 81d82a9be608a01b0a791033b5335748e0fdff61..8a90155862909b5d041d8226355b63c9c6a18e37 100644 (file)
@@ -95,16 +95,23 @@ static inline unsigned long vlc_threadid (void)
 void vlc_pthread_fatal (const char *action, int error,
                         const char *file, unsigned line)
 {
+    char buf[1000];
     const char *msg;
 
     fprintf (stderr, "LibVLC fatal error %s in thread %lu at %s:%u: %d\n",
              action, vlc_threadid (), file, line, error);
     fflush (stderr);
 
-    /* Sometimes strerror() crashes too, so make sure we print an error
+    /* Sometimes strerror_r() crashes too, so make sure we print an error
      * message before we invoke it */
-    msg = strerror (error);
-    fprintf (stderr, "Error description was: \"%s\"\n", msg ? msg : "(null)");
+#ifdef __GLIBC__ && _POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600 && _GNU_SOURCE
+    /* use GNU prototype */
+    msg = strerror_r (error, buf, sizeof (buf));
+#else
+    msg = buf;
+    if (!strerror_r (error, buf, sizeof (buf)))
+#endif
+        fprintf (stderr, "Error description: \"%s\"\n", msg ? msg : "(null)");
     fflush (stderr);
     abort ();
 }