THRIFT-2454: c_glib: There is no gethostbyname_r() in some OS
Patch: Jin-wook Jeong
diff --git a/configure.ac b/configure.ac
index 483c283..f4d1869 100755
--- a/configure.ac
+++ b/configure.ac
@@ -530,6 +530,7 @@
AC_CHECK_FUNCS([bzero])
AC_CHECK_FUNCS([ftruncate])
AC_CHECK_FUNCS([gethostbyname])
+AC_CHECK_FUNCS([gethostbyname_r])
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([memmove])
AC_CHECK_FUNCS([memset])
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c b/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c
index a371ace..68eb21c 100644
--- a/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c
@@ -54,16 +54,24 @@
gboolean
thrift_socket_open (ThriftTransport *transport, GError **error)
{
- struct hostent he, *hp = NULL;
+ struct hostent *hp = NULL;
struct sockaddr_in pin;
int err;
+#if defined(HAVE_GETHOSTBYNAME_R)
+ struct hostent he;
char buf[1024];
+#endif
ThriftSocket *tsocket = THRIFT_SOCKET (transport);
g_return_val_if_fail (tsocket->sd == 0, FALSE);
/* lookup the destination host */
- if (gethostbyname_r(tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL) {
+#if defined(HAVE_GETHOSTBYNAME_R)
+ if (gethostbyname_r (tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL)
+#else
+ if ((hp = gethostbyname (tsocket->hostname)) == NULL && (err = h_errno))
+#endif
+ {
/* host lookup failed, bail out with an error */
g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_HOST,
"host lookup failed for %s:%d - %s",