libwww patch

Enclosed is a patch against the latest CVS to work around the differences
in reentrant libc functions. This fixes some compile problems and coredumps
on Linux, Irix, and AIX.

This patch adds configure-time checks for ctime_r(), readdir_r(),
gethostbyname_r(), gethostbyaddr_r(), and getlogin_r(). 

I also have a couple of minor modifications to some of the html
headers to get them to compile with the AIX compiler. The cast in
HTUtils.html works around the fact that xlc thinks that
0xFFFFFFFF is too large for a 32-bit enumeration value (weird,
yes?).

Finally, there is am increase of the HOSTENT_MAX value. I kept
running into trouble with the DNS resolver with the default
buffer size.

joe

Index: acconfig.h
===================================================================
RCS file: /sources/public/libwww/acconfig.h,v
retrieving revision 1.25
diff -r1.25 acconfig.h
38a39,74
> /* Define to use the two-argument variant of ctime_r */
> #undef HAVE_CTIME_R_2
> 
> /* Define to use the three-argument variant of ctime_r */
> #undef HAVE_CTIME_R_3
> 
> /* Define to use the two-argument variant of readdir_r */
> #undef HAVE_READDIR_R_2
> 
> /* Define to use the three-argument variant of readdir_r */
> #undef HAVE_READDIR_R_3
> 
> /* Define to use the three-argument variant of gethostbyname_r */
> #undef HAVE_GETHOSTBYNAME_R_3
> 
> /* Define to use the five-argument variant of gethostbyname_r */
> #undef HAVE_GETHOSTBYNAME_R_5
> 
> /* Define to use the six-argument variant of gethostbyname_r */
> #undef HAVE_GETHOSTBYNAME_R_6
> 
> /* Define to use the three-argument variant of gethostbyname_r */
> #undef HAVE_GETHOSTBYADDR_R_5
> 
> /* Define to use the five-argument variant of gethostbyname_r */
> #undef HAVE_GETHOSTBYADDR_R_7
> 
> /* Define to use the six-argument variant of gethostbyname_r */
> #undef HAVE_GETHOSTBYADDR_R_8
> 
> /* Define if getlogin_r returns an integer */
> #undef GETLOGIN_R_RETURNS_INT
> 
> /* Define if getlogin_r returns a pointer */
> #undef GETLOGIN_R_RETURNS_POINTER
> 
Index: configure.in
===================================================================
RCS file: /sources/public/libwww/configure.in,v
retrieving revision 1.81
diff -r1.81 configure.in
608a609
>     ac_cv_reentrant=no
612a614
>     ac_cv_reentrant=yes
616a619,914
> 
> if test "$ac_cv_reentrant" = "yes"; then
> 
>     AC_MSG_CHECKING(for ctime_r)
>     if test -z "$ac_cv_ctime_args"; then
>         AC_TRY_COMPILE(
>         [#include <time.h>],
>         [
>             time_t clock;
>             char buf[26];
>             ctime_r(&clock, buf);
>         ], ac_cv_ctime_args=2)
>     fi
>     if test -z "$ac_cv_ctime_args" ; then
>         AC_TRY_COMPILE(
>         [#include <time.h>],
>         [
>             time_t clock;
>             char buf[26];
>             ctime_r(&clock, buf, 26);
>         ], ac_cv_ctime_args=3)
>     fi
>     if test -z "$ac_cv_ctime_args"; then
>         AC_MSG_RESULT(no)
>         have_missing_r_funcs="$have_missing_r_funcs ctime_r"
>     else
>         if test "$ac_cv_ctime_args" = 2; then
>             AC_DEFINE(HAVE_CTIME_R_2)
>         elif test "$ac_cv_ctime_args" = 3; then
>             AC_DEFINE(HAVE_CTIME_R_3)
>         fi
>         AC_MSG_RESULT([yes, and it takes $ac_cv_ctime_args arguments])
>     fi
> 
>     AC_MSG_CHECKING(for readdir_r)
>     if test -z "$ac_cv_readdir_args"; then
>         AC_TRY_COMPILE(
> 	[
> #include <sys/types.h>
> 
> #if defined(HAVE_DIRENT_H)
> #   include <dirent.h>
> #   define NAMLEN(dirent) strlen((dirent)->d_name)
> #else
> #   define dirent direct
> #   define NAMLEN(dirent) (dirent)->d_namlen
> #   if defined(HAVE_SYS_NDIR_H)
> #       include <sys/ndir.h>
> #   endif
> #   if defined(HAVE_SYS_DIR_H)
> #       include <sys/dir.h>
> #   endif
> #   if defined(HAVE_NDIR_H)
> #       include <ndir.h>
> #   endif
> #endif  ],
>         [
>         struct dirent dir, *dirp;
>         DIR *mydir;
>         dirp = readdir_r(mydir, &dir);
> 	], ac_cv_readdir_args=2)
>     fi
>     if test -z "$ac_cv_readdir_args"; then
> 	
>         AC_TRY_COMPILE(
>         [
> #include <sys/types.h>
> #if defined(HAVE_DIRENT_H)
> #   include <dirent.h>
> #   define NAMLEN(dirent) strlen((dirent)->d_name)
> #else
> #   define dirent direct
> #   define NAMLEN(dirent) (dirent)->d_namlen
> #   if defined(HAVE_SYS_NDIR_H)
> #       include <sys/ndir.h>
> #   endif
> #   if defined(HAVE_SYS_DIR_H)
> #       include <sys/dir.h>
> #   endif
> #   if defined(HAVE_NDIR_H)
> #       include <ndir.h>
> #   endif
> #endif  ],
>         [
>         struct dirent dir, *dirp;
>         DIR *mydir;
>         int rc;
>         rc = readdir_r(mydir, &dir, &dirp);
>         ], ac_cv_readdir_args=3)
>     fi
> 
>     if test -z "$ac_cv_readdir_args"; then
>         AC_MSG_RESULT(no)
>         have_missing_r_funcs="$have_missing_r_funcs readdir_r"
>     else
>         if test "$ac_cv_readdir_args" = 2; then
>             AC_DEFINE(HAVE_READDIR_R_2)
>         elif test "$ac_cv_readdir_args" = 3; then
>             AC_DEFINE(HAVE_READDIR_R_3)
>         fi
>         AC_MSG_RESULT([yes, and it takes $ac_cv_readdir_args arguments])
>     fi
> 
>     AC_MSG_CHECKING(for gethostbyname_r)
>     if test -z "$ac_cv_gethostbyname_args"; then
>         AC_TRY_COMPILE(
> 	    [
> #include <sys/types.h>
> #include <netdb.h>],
> 	    [
> struct hostent *hp;
> struct hostent h;
> char *name;
> char buffer[10];
> int  h_errno;
> hp = gethostbyname_r(name, &h, buffer, 10, &h_errno);],
>             ac_cv_gethostbyname_args=5)
>     fi
>     if test -z "$ac_cv_gethostbyname_args"; then
>         AC_TRY_COMPILE(
> 	    [
> #include <sys/types.h>
> #include <netdb.h>],
> 	    [
> struct hostent h;
> struct hostent_data hdata;
> char *name;
> int  rc;
> rc = gethostbyname_r(name, &h, &hdata);],
>             ac_cv_gethostbyname_args=3)
>     fi
>     if test -z "$ac_cv_gethostbyname_args"; then
>         AC_TRY_COMPILE(
> 	    [
> #include <sys/types.h>
> #include <netdb.h>],
> 	    [
> struct hostent h;
> struct hostent *hp;
> char *name;
> char buf[10];
> int rc;
> int h_errno;
> 
> rc = gethostbyname_r(name, &h, buf, 10, &hp, &h_errno);
> 	    ],
> 	    ac_cv_gethostbyname_args=6)
>     fi
>     if test -z "$ac_cv_gethostbyname_args"; then
>         AC_MSG_RESULT(no)
>         have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"
>     else
>         if test "$ac_cv_gethostbyname_args" = 3; then
>             AC_DEFINE(HAVE_GETHOSTBYNAME_R_3)
>         elif test "$ac_cv_gethostbyname_args" = 5; then
>             AC_DEFINE(HAVE_GETHOSTBYNAME_R_5)
>         elif test "$ac_cv_gethostbyname_args" = 6; then
>             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6)
>         fi
>         AC_MSG_RESULT([yes, and it takes $ac_cv_gethostbyname_args arguments])
>     fi
> 
>     AC_MSG_CHECKING(for gethostbyaddr_r)
>     if test -z "$ac_cv_gethostbyaddr_args"; then
> 	AC_TRY_COMPILE(
> 	    [
> #include <sys/types.h>
> #include <netdb.h>],
> 	    [
>                 char * address;
>                 int length;
>                 int type;
>                 struct hostent h;
>                 struct hostent_data hdata;
>                 int rc;
>                 rc = gethostbyaddr_r(address, length, type, &h, &hdata);
> 	    ],
> 	    ac_cv_gethostbyaddr_args=5)
> 	
>     fi
>     if test -z "$ac_cv_gethostbyaddr_args"; then
> 	AC_TRY_COMPILE(
> 	    [
> #include <sys/types.h>
> #include <netdb.h>],
> 	    [
>                 char * address;
>                 int length;
>                 int type;
>                 struct hostent h;
> 		char buffer[10];
> 		int buflen;
> 		int h_errnop;
> 		struct hostent * hp;
> 
> 		hp = gethostbyaddr_r(address, length, type, &h,
> 				     buffer, buflen, &h_errnop);
> 	    ],
> 	    ac_cv_gethostbyaddr_args=7)
>     fi
> 
>     if test -z "$ac_cv_gethostbyaddr_args"; then
> 	AC_TRY_COMPILE(
> 	    [
> #include <sys/types.h>
> #include <netdb.h>],
> 	    [
>                 char * address;
>                 int length;
>                 int type;
>                 struct hostent h;
> 		char buffer[10];
> 		int buflen;
> 		int h_errnop;
> 		struct hostent * hp;
> 		int rc;
> 
> 		rc = gethostbyaddr_r(address, length, type, &h,
> 				     buffer, buflen, &hp, &h_errnop);
> 	    ],
> 	    ac_cv_gethostbyaddr_args=8)
>     fi
>     if test -z "$ac_cv_gethostbyaddr_args"; then
>         AC_MSG_RESULT(no)
>         have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"
>     else
>         if test "$ac_cv_gethostbyaddr_args" = 5; then
>             AC_DEFINE(HAVE_GETHOSTBYADDR_R_5)
>         elif test "$ac_cv_gethostbyaddr_args" = 7; then
>             AC_DEFINE(HAVE_GETHOSTBYADDR_R_7)
>         elif test "$ac_cv_gethostbyaddr_args" = 8; then
>             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8)
>         fi
>         AC_MSG_RESULT([yes, and it takes $ac_cv_gethostbyaddr_args arguments])
>     fi
> 
>     AC_MSG_CHECKING(for getlogin_r)
>     if test -z "$ac_cv_getlogin_r_style"; then
> 	AC_TRY_RUN(
> 	    [
> #include <unistd.h>
> 
> int main()
> {
>     char name[1024];
>     int len=1024;
>     int rc;
>     char *login;
> 
>     name[0]='\0';
> 
>     rc = getlogin_r(name, len);
>     if(rc == 0 && name[0] != '\0')
>     {
> 	return 0; /* returns zero on success */
>     }
>     else if(rc != 0 && name[0] == '\0')
>     {
> 	return 0; /* returns errno on failure */
>     }
>     else if(rc == 0 && name[0] == '\0')
>     {
> 	return 0; /* can't tell */
>     }
>     else if(rc != 0 && name[0] != '\0')
>     {
> 	return 1; /* returns pointer on success */
>     }
> }
> 	    ],
> 	    [
> 		ac_cv_getlogin_r_style=1
> 	    ],
> 	    [
> 		ac_cv_getlogin_r_style=2
> 	    ])
>     fi
>     if test -z "$ac_cv_getlogin_r_style"; then
> 	AC_MSG_RESULT(no)
>         have_missing_r_funcs="$have_missing_r_funcs getlogin_r"
>     else
> 	if test $ac_cv_getlogin_r_style = 1; then
> 	    AC_DEFINE(GETLOGIN_R_RETURNS_INT)
> 	    AC_MSG_RESULT([yes, and it returns an int])
> 	elif test $ac_cv_getlogin_r_style = 2; then
> 	    AC_DEFINE(GETLOGIN_R_RETURNS_POINTER)
> 	    AC_MSG_RESULT([yes, and it returns a pointer])
> 	else
> 	    AC_MSG_RESULT(no: result is $ac_cv_getlogin_r_style)
>             have_missing_r_funcs="$have_missing_r_funcs getlogin_r"
> 	fi
>     fi
>     if test -n "$have_missing_r_funcs"; then
>         AC_MSG_WARN(missing reentrant functions: $have_missing_r_funcs)
>     fi
> fi
Index: Library/src/HTDNS.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTDNS.c,v
retrieving revision 2.30
diff -r2.30 HTDNS.c
284a285,289
> #endif
> #ifdef GETHOSTBYNAME_R_3
>         struct hostent_data hdata;
> #endif
> 
285a291
> #ifdef GETHOSTBYNAME_R_5
287a294,306
> #elif defined(GETHOSTBYNAME_R_6)
> 	gethostbyname_r(hostname, &result, buffer,
> 		        HOSTENT_MAX, &hostelement, &thd_errno);
> 
> #elif defined(GETHOSTBYNAME_R_3)
>         if(gethostbyname_r(hostname, &result, &hdata) == 0)
> 	{
> 	    hostelement = &result;
> 	}
> 	else
> 	{
> 	    hostelement = NULL;
> 	}
320a340,342
> #ifdef HAVE_GETHOSTBYADDR_R_5
>     struct hostent_data hdata;
> #endif
329c351
< #ifdef HT_REENTRANT
---
> #ifdef HAVE_GETHOSTBYADDR_R_7
331a354,366
> #elif defined(HAVE_GETHOSTBYADDR_R_8)
>     gethostbyaddr_r((char *) iaddr, sizeof(struct in_addr), AF_INET,
> 		    &result, buffer, HOSTENT_MAX, &phost, &thd_errno);
> #elif defined(HAVE_GETHOSTBYADDR_R_5)
>     if(gethostbyaddr_r((char *) iaddr, sizeof(struct in_addr), AF_INET,
> 		    &result, &hdata)==0)
>     {
> 	phost=&result;
>     }
>     else
>     {
> 	phost = NULL;
>     }
Index: Library/src/HTFile.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTFile.c,v
retrieving revision 1.154
diff -r1.154 HTFile.c
177c177,182
< 	while ((dirbuf = (struct dirent *) readdir_r(dp, &result)))
---
> #endif
> 
> #ifdef HAVE_READDIR_R_2
>         while ((dirbuf = (struct dirent *) readdir_r(dp, &result)))
> #elif defined(HAVE_READDIR_R_3)
>         while (readdir_r(dp, &result, &dirbuf) == 0)
180c185
< #endif /* HT_REENTRANT */
---
> #endif /* HAVE_READDIR_R_2 */
Index: Library/src/HTInet.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTInet.c,v
retrieving revision 2.27
diff -r2.27 HTInet.c
405a406
>   int result;
427c428
< #ifdef HT_REENTRANT
---
> #ifdef GETLOGIN_R_RETURNS_POINTER
428a430,435
> #elif defined(GETLOGIN_R_RETURNS_INT)
>     if (!login && (result = getlogin_r(name, HT_LOGNAME_MAX)) == 0)
>     {
> 	login = &name[0];
>     }
>     else
Index: Library/src/HTMLPDTD.html
===================================================================
RCS file: /sources/public/libwww/Library/src/HTMLPDTD.html,v
retrieving revision 2.31
diff -r2.31 HTMLPDTD.html
321c321
< 	HTML_ATTRIBUTES(BUTTON),
---
> 	HTML_ATTRIBUTES(BUTTON)
Index: Library/src/HTMulti.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTMulti.c,v
retrieving revision 2.35
diff -r2.35 HTMulti.c
336c336
< #ifdef HT_REENTRANT
---
> #ifdef HAVE_READDIR_R_2
337a338,339
> #elif defined(HAVE_READDIR_R_3)
>         while (readdir_r(dp, &result, &dirbuf) == 0) {
340c342
< #endif /* HT_REENTRANT */
---
> #endif /* HAVE_READDIR_R_2 */
Index: Library/src/HTUtils.html
===================================================================
RCS file: /sources/public/libwww/Library/src/HTUtils.html,v
retrieving revision 2.91
diff -r2.91 HTUtils.html
121c121
<     SHOW_ALL_TRACE	= 0xFFFFFFFF
---
>     SHOW_ALL_TRACE	= (int) 0xFFFFFFFF
Index: Library/src/HTWWWStr.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTWWWStr.c,v
retrieving revision 2.35
diff -r2.35 HTWWWStr.c
470c470,474
< #ifdef HT_REENTRANT
---
> #if defined (HAVE_CTIME_R_2)
> 		    char buffer[CTIME_MAX];
> 		    HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _
> 			    str _ (long) t _ (char *) ctime_r(&t, buffer));
> #elif defined(HAVE_CTIME_R_3)
Index: Library/src/wwwsys.html
===================================================================
RCS file: /sources/public/libwww/Library/src/wwwsys.html,v
retrieving revision 2.123
diff -r2.123 wwwsys.html
1395c1395
< #define HOSTENT_MAX	128
---
> #define HOSTENT_MAX	1024

Received on Thursday, 18 November 1999 22:58:50 UTC