Commit 34c5c0e1 by Alexandre Oliva Committed by Tom Tromey

configure.in: Check for struct hostent_data and need for -D_REENTRANT for gethostbyname_r...

1999-07-31  Alexandre Oliva  <oliva@dcc.unicamp.br>

	* configure.in: Check for struct hostent_data and need for
	-D_REENTRANT for gethostbyname_r declaration.
	* java/net/natInetAddress.cc: Define _REENTRANT if needed.
	(lookup): Use hostent_data for fixed_buffer.
	* configure, include/config.h.in: Rebuilt.

From-SVN: r28369
parent 5f67f48f
1999-07-31 Alexandre Oliva <oliva@dcc.unicamp.br>
* configure.in: Check for struct hostent_data and need for
-D_REENTRANT for gethostbyname_r declaration.
* java/net/natInetAddress.cc: Define _REENTRANT if needed.
(lookup): Use hostent_data for fixed_buffer.
* configure, include/config.h.in: Rebuilt.
1999-07-31 Alexandre Oliva <oliva@dcc.unicamp.br>
* java/lang/natSystem.cc (arraycopy): Use bcopy if memmove is not
available. Don't cast memmove args to (void*).
* configure.in: Do not abort if memmove is not available.
......
......@@ -309,7 +309,48 @@ else
# We look for the one that returns `int'.
# Hopefully this check is robust enough.
AC_EGREP_HEADER(int.*gethostbyname_r, netdb.h, [
AC_DEFINE(GETHOSTBYNAME_R_RETURNS_INT)])])
AC_DEFINE(GETHOSTBYNAME_R_RETURNS_INT)])
case " $GCINCS " in
*" -D_REENTRANT "*) ;;
*)
dnl On DU4.0, gethostbyname_r is only declared with -D_REENTRANT
AC_CACHE_CHECK([whether gethostbyname_r declaration requires -D_REENTRANT],
[libjava_cv_gethostbyname_r_needs_reentrant],
[ AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_TRY_COMPILE([#include <netdb.h>],
[gethostbyname_r("", 0, 0);],
[libjava_cv_gethostbyname_r_needs_reentrant=no], [dnl
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -D_REENTRANT"
AC_TRY_COMPILE([#include <netdb.h>], [gethostbyname_r("", 0, 0);],
[libjava_cv_gethostbyname_r_needs_reentrant=yes],
[libjava_cv_gethostbyname_r_needs_reentrant=fail])
CPPFLAGS="$CPPFLAGS_SAVE"
])
AC_LANG_RESTORE
])
if test "x$libjava_cv_gethostbyname_r_needs_reentrant" = xyes; then
AC_DEFINE(GETHOSTBYNAME_R_NEEDS_REENTRANT, 1, [Define if gethostbyname_r is only declared if _REENTRANT is defined])
fi
;;
esac
AC_CACHE_CHECK([for struct hostent_data],
[libjava_cv_struct_hostent_data], [dnl
AC_TRY_COMPILE([
#if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
# define _REENTRANT 1
#endif
#include <netdb.h>], [struct hostent_data data;],
[libjava_cv_struct_hostent_data=yes],
[libjava_cv_struct_hostent_data=no])])
if test "x$libjava_cv_struct_hostent_data" = xyes; then
AC_DEFINE(HAVE_STRUCT_HOSTENT_DATA, 1,
[Define if struct hostent_data is defined in netdb.h])
fi
])
AC_CHECK_FUNCS(gethostbyaddr_r, [
AC_DEFINE(HAVE_GETHOSTBYADDR_R)
......
......@@ -268,3 +268,9 @@
/* Version number of package */
#undef VERSION
/* Define if gethostbyname_r is only declared if _REENTRANT is defined */
#undef GETHOSTBYNAME_R_NEEDS_REENTRANT
/* Define if struct hostent_data is defined in netdb.h */
#undef HAVE_STRUCT_HOSTENT_DATA
......@@ -10,6 +10,10 @@ details. */
#include <config.h>
#if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
# define _REENTRANT 1
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
......@@ -97,6 +101,9 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
struct hostent *hptr = NULL;
#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
struct hostent hent_r;
#if HAVE_STRUCT_HOSTENT_DATA
struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
#else
#if defined (__GLIBC__)
// FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
// ERANGE to errno if the buffer size is too small, rather than what is
......@@ -109,6 +116,7 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
char *buffer_r = fixed_buffer;
int size_r = sizeof (fixed_buffer);
#endif
#endif
if (host != NULL)
{
......@@ -122,10 +130,13 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
JvGetStringUTFRegion (host, 0, host->length(), hostname);
buf[len] = '\0';
#ifdef HAVE_GETHOSTBYNAME_R
int herr = 0;
while (true)
{
int ok;
#if HAVE_STRUCT_HOSTENT_DATA
ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
#else
int herr = 0;
#ifdef GETHOSTBYNAME_R_RETURNS_INT
ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
&hptr, &herr);
......@@ -139,6 +150,7 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
}
else
#endif /* HAVE_STRUCT_HOSTENT_DATA */
break;
}
#else
......@@ -171,10 +183,13 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
JvFail ("unrecognized size");
#ifdef HAVE_GETHOSTBYADDR_R
int herr = 0;
while (true)
{
int ok;
#if HAVE_STRUCT_HOSTENT_DATA
ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
#else
int herr = 0;
#ifdef GETHOSTBYADDR_R_RETURNS_INT
ok = ! gethostbyaddr_r (val, len, type, &hent_r,
buffer_r, size_r, &hptr, &herr);
......@@ -189,6 +204,7 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
}
else
#endif /* HAVE_STRUCT_HOSTENT_DATA */
break;
}
#else /* HAVE_GETHOSTBYADDR_R */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment