On Fri, Nov 17, 2000 at 07:30:15PM +0000, John Levon wrote:
> On Fri, 17 Nov 2000, Kayvan Sylvan wrote:
> 
> > Yes, I have grepped through the headers. No, this is not a mis-installed
> > system. This is a generic SunOS 5.5.1 system (not SunOS 5.7).
> 
> OK, then there should be a mkstemp.h header file which either does nothing
> (or includes cstdlib) or includes what you need for your platform,
> depending on an autoconf test. It's just not right to include what you
> have on platforms that define it already...
> 
> IMHO of course

There should be two definitions, HAVE_MKSTEMP and HAVE_MKSTEMP_PROTO.
KDE 2.0 (kdesupport) does not compile "out of the box" under Solaris
2.5.1 due to a similar conflict of gethostname. Solaris 2.5.1 has
gethostname but no function prototype. The solution is the following
autoconf macro:

AC_DEFUN(AC_CHECK_GETHOSTNAME,
[
AC_LANG_CPLUSPLUS
save_CXXFLAGS="$CXXFLAGS"
if test "$GCC" = "yes"; then
CXXFLAGS="$CXXFLAGS -pedantic-errors"
fi

AC_MSG_CHECKING([for gethostname])
AC_CACHE_VAL(ac_cv_func_gethostname,
[
AC_TRY_LINK([
#include <stdlib.h>
#include <unistd.h>
],
[
char buffer[200];
gethostname(buffer, 200);
],
ac_cv_func_gethostname=yes,
ac_cv_func_gethostname=no)
])
AC_MSG_RESULT($ac_cv_func_gethostname)

AC_MSG_CHECKING([if gethostname needs custom prototype])
AC_CACHE_VAL(ac_cv_proto_gethostname,
[
if eval "test \"`echo $ac_cv_func_gethostname`\" = yes"; then
  ac_cv_proto_gethostname=no
else
  AC_TRY_LINK([
#include <stdlib.h>
#include <unistd.h>

extern "C" int gethostname (char *, int);
],
[
char buffer[200];
gethostname(buffer, 200);
],
  ac_cv_func_gethostname=yes
  ac_cv_proto_gethostname=yes,
  AC_MSG_RESULT([fatal error])
  AC_MSG_ERROR(gethostname unavailable))
fi
])
AC_MSG_RESULT($ac_cv_proto_gethostname)
if eval "test \"`echo $ac_cv_func_gethostname`\" = yes"; then
  AC_DEFINE(HAVE_GETHOSTNAME, 1, [Define if you have gethostname])
fi
if eval "test \"`echo $ac_cv_proto_gethostname`\" = no"; then
  AC_DEFINE(HAVE_GETHOSTNAME_PROTO, 1,
  [Define if you have gethostname prototype])
fi
CXXFLAGS="$save_CXXFLAGS"
])

This is used by the following entry in config.h to define the function
prototype for gethostname:

#ifndef HAVE_GETHOSTNAME_PROTO
#ifdef __cplusplus  
extern "C" 
#endif
int gethostname (char *Name, int Namelen);
#endif  

I would like to see this solution rather than those already discussed.
This has a much better chance of working cross-platform. Of course,
someone will need to modify the above (basically
s/gethostname/mkstemp/).

-- 
albert chin ([EMAIL PROTECTED])

-

Reply via email to