[glib] Make g_strerror work with non-glibc POSIX systems



commit ebf961a58d540ea40611ad75bc983f5386d3635b
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat Sep 5 23:35:57 2015 +0800

    Make g_strerror work with non-glibc POSIX systems
    
    We should only use GNU-specific strerror_r on glibc. On other systems,
    we should use the XSI-compliant version.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754601

 glib/gstrfuncs.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c
index f1085a1..2f0cda1 100644
--- a/glib/gstrfuncs.c
+++ b/glib/gstrfuncs.c
@@ -1258,14 +1258,19 @@ g_strerror (gint errnum)
   gint saved_errno = errno;
   GError *error = NULL;
 
-  /* Since we are building with _GNU_SOURCE, we get the
-   * GNU variant of strerror_r (with glibc).
-   */
 #ifdef G_OS_WIN32
   strerror_s (buf, sizeof (buf), errnum);
   msg = buf;
-#else
+  /* If we're using glibc, since we are building with _GNU_SOURCE, we
+   * expect to get the GNU variant of strerror_r.  However, use the
+   * provided check from man strerror_r(3) in case we ever stop using
+   * _GNU_SOURCE (admittedly unlikely).
+   */
+#elif (defined __GLIBC__) && !((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
   msg = strerror_r (errnum, buf, sizeof (buf));
+#else
+  strerror_r (errnum, buf, sizeof (buf));
+  msg = buf;
 #endif
   if (!g_get_charset (NULL))
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]