[glib: 1/2] Fix build on old libc that does not define _SC_HOST_NAME_MAX



commit de799582950a5aa543d4ff8ef9d39928f3399af8
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Fri Nov 15 10:28:44 2019 -0500

    Fix build on old libc that does not define _SC_HOST_NAME_MAX
    
    Bionic (Android's libc) only added that symbol in Nov 2014, can't find
    in which NDK release it got released.

 glib/gutils.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/glib/gutils.c b/glib/gutils.c
index 33baa1737..6c89fc4cc 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -993,6 +993,7 @@ g_get_host_name (void)
       const gsize size_large = (gsize) 256 * 256;
       gchar *tmp;
 
+#ifdef _SC_HOST_NAME_MAX
       max = sysconf (_SC_HOST_NAME_MAX);
       if (max > 0 && max <= G_MAXSIZE - 1)
         size = (gsize) max + 1;
@@ -1001,8 +1002,11 @@ g_get_host_name (void)
         size = HOST_NAME_MAX + 1;
 #else
         size = _POSIX_HOST_NAME_MAX + 1;
-#endif
-
+#endif /* HOST_NAME_MAX */
+#else
+      /* Fallback to some reasonable value */
+      size = 256;
+#endif /* _SC_HOST_NAME_MAX */
       tmp = g_malloc (size);
       failed = (gethostname (tmp, size) == -1);
       if (failed && size < size_large)


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