# -*- autoconf -*-
#########################################
##
# Checks for library functions.
##
#########################################

##
#   Standard checks:
##
AC_FUNC_ALLOCA          #  alloca()
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP          #  memcmp()   -  obs
AC_TYPE_SIGNAL
AC_FUNC_GETMNTENT

##
#   Stand-alone function checks:
##
#  Core:
AC_CHECK_FUNCS([lrand48         rand          random    ] dnl
               [signal          sigset                  ] )

#  Library:
AC_CHECK_FUNCS([fork            gai_strerror                   ] dnl
               [getaddrinfo     gethostname   gethostbyname    ] dnl
               [getipnodebyname               gettimeofday     ] dnl
               [if_nametoindex  mkstemp       regcomp          ] dnl
               [setenv          setitimer     setlocale        ] dnl
               [setsid          snprintf                       ] dnl
               [strcasestr                    strdup           ] dnl
               [strerror        strlcpy       strncasecmp      ] dnl
               [strtok_r        strtol        strtoul          ] dnl
               [strtoull        sysconf       times            ] dnl
               [vsnprintf                                      ] )

#  Agent:
AC_CHECK_FUNCS([cgetnext        execv         gai_strerror     ] dnl
               [getfsstat       getgrnam      gethostname      ] dnl
               [                getloadavg                     ] dnl
               [getpid          getpwnam      getvfsstat       ] dnl
               [hasmntopt       initgroups                     ] dnl
               [if_nameindex    if_nametoindex                 ] dnl
               [mkstemp         mktime                         ] dnl
               [poll            regcomp                        ] dnl
               [setgid          setgroups                      ] dnl
               [setmntent       setuid                         ] dnl
               [sigaction       sigblock      sighold          ] dnl
               [statfs          statvfs       stime            ] dnl
               [strncasecmp     system                         ] dnl
               [uname           usleep                         ] )

#  Apps:
AC_CHECK_FUNCS([getdtablesize                                  ] dnl
               [getgrnam        getpid        getpwnam         ] dnl
               [setgid          setgroups     setuid           ] dnl
               [tcgetattr                                      ] )

#  Not-Used:
AC_CHECK_FUNCS([if_freenameindex              getpagesize      ] dnl
               [lseek64         pread64                        ] dnl
               [select          sigalrm       socket           ] )


##
#   More complex function checks:
#           (Agent)
##

#       rpmGetPath check needs clean LIBS environment   (Linux)
#
if test "x$with_rpm" != "xno" && \
        echo " $module_list " | $GREP " host/hr_swinst " > /dev/null; then
    OLDLIBS=$LIBS
    LIBS=$LMIBLIBS
    AC_CHECK_FUNCS(rpmGetPath)
    LIBS=$OLDLIBS
fi

#       statfs( char *, struct fs_data* )               (Ultrix)
#
AC_MSG_CHECKING([[for two-argument statfs with struct fs_data (Ultrix)]])
AC_CACHE_VAL(
    fu_cv_sys_stat_fs_data,
    [AC_TRY_RUN([
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_FS_TYPES_H
#include <sys/fs_types.h>
#endif
main ()
{
struct fs_data fsd;
/* Ultrix's statfs returns 1 for success,
   0 for not mounted, -1 for failure.  */
exit (statfs (".", &fsd) != 1);
}],
    fu_cv_sys_stat_fs_data=yes,
    fu_cv_sys_stat_fs_data=no,
    fu_cv_sys_stat_fs_data=no)])
AC_MSG_RESULT($fu_cv_sys_stat_fs_data)
if test $fu_cv_sys_stat_fs_data = yes; then
    AC_DEFINE(STAT_STATFS_FS_DATA, 1,
        [Define if statfs takes 2 args and the second argument has
         type struct fs_data. @<:@Ultrix@:>@])
fi


##
#   Other function-related checks:
#           (general build)
##

#       How to get the name of the current function
#
AC_CACHE_CHECK([how to get the name of the current function],
               [netsnmp_cv__func__name],[
    netsnmp_cv__func__name=no
    AC_COMPILE_IFELSE(
        AC_LANG_PROGRAM(,[[const char* cp = __func__;]]),
        [netsnmp_cv__func__name=__func__])
    if test "$netsnmp_cv__func__name" = no ; then
      AC_COMPILE_IFELSE(
        AC_LANG_PROGRAM(,[[const char* cp = __FUNCTION__;]]),
        [netsnmp_cv__func__name=__FUNCTION__])
    fi])
if test "$netsnmp_cv__func__name" != no; then
    AC_DEFINE_UNQUOTED([NETSNMP_FUNCTION],[$netsnmp_cv__func__name],
        [Should evaluate to the name of the current function if defined])
fi


#       Whether static inline functions are broken      (SCO Unixware)
#
AC_CACHE_CHECK([[whether static inline functions are broken (Unixware)]],
                [netsnmp_cv_c_broken_inline],
    AC_COMPILE_IFELSE([[
static inline int nested_inline_function(void) {
  return 0;
}
inline int main_inline_function( void ) {
  return nested_inline_function();
}
    ]],
    netsnmp_cv_broken_inline=no,
    netsnmp_cv_broken_inline=yes))


#       Yes -  static inline functions are broken       (Solaris 2.x)
#
case "$target_os" in
    solaris*)
        netsnmp_cv_broken_inline=yes
        ;;
    *)
        ;;
esac

if test "$netsnmp_cv_broken_inline" = yes ; then
  AC_DEFINE(NETSNMP_BROKEN_INLINE, 1,
        [Define if static inline functions are unsupported])
fi


##
#   Mis-placed (non-function) checks:
##

AC_CACHE_CHECK([for SIOCGIFADDR in sys/ioctl.h],
               netsnmp_cv_sys_ioctl_h_has_SIOCGIFADDR,
    AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifndef SIOCGIFADDR
No SIOCGIFADDR found here.
#endif
        ]])],
    [netsnmp_cv_sys_ioctl_h_has_SIOCGIFADDR=yes],
    [netsnmp_cv_sys_ioctl_h_has_SIOCGIFADDR=no]))
if test $netsnmp_cv_sys_ioctl_h_has_SIOCGIFADDR = yes; then
  AC_DEFINE(SYS_IOCTL_H_HAS_SIOCGIFADDR, 1,
   [define if SIOCGIFADDR exists in sys/ioctl.h])
fi

