Re: Compiling on HP-UX 10.20 fails - Mailing list pgsql-hackers
From | Andrew Chernow |
---|---|
Subject | Re: Compiling on HP-UX 10.20 fails |
Date | |
Msg-id | 491FB014.80100@esilo.com Whole thread Raw |
In response to | Re: Compiling on HP-UX 10.20 fails (Tom Lane <tgl@sss.pgh.pa.us>) |
Responses |
Re: Compiling on HP-UX 10.20 fails
|
List | pgsql-hackers |
Tom Lane wrote: > Andrew Chernow <ac@esilo.com> writes: >> I am trying to compile libpq on HP-UX 10.20 using gcc 2.95.3, cpu is a >> 400MHz PA8500. I'm using the 8.3.5 tarball. > > Yeah, 10.20 is a bit old and creaky, and the system headers are shy of a > load in a few places. I currently use the attached fixes. > > regards, tom lane > That got rid of all warnings. Although, it still fails to compile due to gethostbyname_r: thread.c:141: too many arguments to function `gethostbyname_r' hpux 10.20, hpux 11 and aix (maybe more) use a 3 argument version, not 5: int gethostbyname_r(const char *name, struct hostent *result, struct hostent_data *buffer); I supplied a patch that includes a configure check. NOTE: the hpux platform check at the top of thread.c may not be cross-compiler, I think they are from gcc. Does the postgresql config system define platform somewhere so I can #ifdef PG_HPUX? -- Andrew Chernow eSilo, LLC every bit counts http://www.esilo.com/ Index: configure.in =================================================================== RCS file: /projects/cvsroot/pgsql/configure.in,v retrieving revision 1.571 diff -C6 -r1.571 configure.in *** configure.in 30 Oct 2008 12:28:51 -0000 1.571 --- configure.in 16 Nov 2008 05:15:59 -0000 *************** *** 1363,1374 **** --- 1363,1392 ---- if test "$PORTNAME" != "win32"; then AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([pthread.h not found, required for --enable-thread-safety])]) fi AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r]) + # determines if the system has a 3 or 5 argument gethostbyname_r, only needed with threads + # there is also a 6 arg version used by linux + if test "$enable_thread_safety" = yes ; then + AC_MSG_CHECKING([gethostbyname_r argument count]) + AC_TRY_COMPILE( + [#undef _XOPEN_SOURCE_EXTENDED + #ifndef _REENTRANT + #define _REENTRANT + #endif + #ifndef _THREAD_SAFE + #define _THREAD_SAFE + #endif + #include <netdb.h>], + [gethostbyname_r((void *)0, (void *)0, (void *)0)], + [AC_DEFINE(GETHOSTBYNAME_R_ARGCNT, 3, [Define to the number of arguments gethostbyname_r accepts]) AC_MSG_RESULT(3)], + [AC_DEFINE(GETHOSTBYNAME_R_ARGCNT, 5, [Define to the number of arguments gethostbyname_r accepts]) AC_MSG_RESULT(5)]) + fi + # Do test here with the proper thread flags PGAC_FUNC_GETPWUID_R_5ARG PGAC_FUNC_STRERROR_R_INT CFLAGS="$_CFLAGS" LIBS="$_LIBS" Index: src/port/thread.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/port/thread.c,v retrieving revision 1.39 diff -C6 -r1.39 thread.c *** src/port/thread.c 22 Apr 2008 13:06:57 -0000 1.39 --- src/port/thread.c 16 Nov 2008 05:16:00 -0000 *************** *** 9,20 **** --- 9,27 ---- * * $PostgreSQL: pgsql/src/port/thread.c,v 1.39 2008/04/22 13:06:57 mha Exp $ * *------------------------------------------------------------------------- */ + /* When _XOPEN_SOURCE_EXTENDED is defined, struct hostent_data does + * not get declared. This structure is needed by hpux gethostbyname_r. + */ + #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && (defined(__hpux) || defined(__hpux__) || defined(hpux)) + #undef _XOPEN_SOURCE_EXTENDED + #endif + #include "c.h" #include <pwd.h> #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) #endif *************** *** 126,142 **** --- 133,171 ---- char *buffer, size_t buflen, struct hostent ** result, int *herrno) { #if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_GETHOSTBYNAME_R) + #if GETHOSTBYNAME_R_ARGCNT == 3 + *result = NULL; + + if (buflen < sizeof(struct hostent_data)) + { + /* linux man page says this gets set when buffer is too small */ + *herrno = ERANGE; + return -1; + } + + if (gethostbyname_r(name, resultbuf, (struct hostent_data *)buffer)) + { + *herrno = h_errno; + return -1; + } + + *result = resultbuf; + + /* 5 argument version. There is also a 6 arg version found on linux. */ + #else /* * broken (well early POSIX draft) gethostbyname_r() which returns 'struct * hostent *' */ *result = gethostbyname_r(name, resultbuf, buffer, buflen, herrno); + #endif /* GETHOSTBYNAME_R_ARGCNT */ + return (*result == NULL) ? -1 : 0; #else /* no gethostbyname_r(), just use gethostbyname() */ *result = gethostbyname(name);
pgsql-hackers by date: