dnl Check for su
AC_PATH_PROG(path_su, "su", "no")
if test "$path_su" = "no"; then
    AC_MSG_WARN(su was not found)
else
    AC_DEFINE_UNQUOTED(__PATH_SU, "$path_su", [path to su])
fi

dnl Check for sudo
AC_PATH_PROG(path_sudo, "sudo", "no")
if test "$path_sudo" = "no"; then
    AC_MSG_WARN(sudo was not found)
else
    AC_DEFINE_UNQUOTED(__PATH_SUDO, "$path_sudo", [path to sudo])
fi

AC_ARG_WITH(sudo-tdesu-backend,
	    AC_HELP_STRING([--with-sudo-tdesu-backend],
			   [use sudo as backend for tdesu (default is su)]),
[
    if test x$withval = xyes; then
        use_tdesu_backend="sudo"
    else
        use_tdesu_backend="su"
    fi
],
    use_tdesu_backend="su"
)

if test x$use_tdesu_backend = xsudo -a x$path_sudo = xno; then
    AC_MSG_ERROR(sudo was chosen as tdesu backend, but was not found in path.)
fi

AC_DEFINE_UNQUOTED(DEFAULT_SUPER_USER_COMMAND, "$use_tdesu_backend", [Use su or sudo])

dnl Check for POSIX.1b scheduling
AC_MSG_CHECKING([POSIX.1b scheduling])
AC_TRY_LINK([
    #include <sched.h>
],
[
    sched_getscheduler(0);
],
have_rtsched="yes", have_rtsched="no")
if test "$have_rtsched" = "yes"; then
    AC_DEFINE(POSIX1B_SCHEDULING, 1, [Define if you have POSIX.1b scheduling])
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi

dnl Check for initgroups()
AC_CHECK_FUNCS(initgroups)

dnl openpty stuff
AC_CHECK_HEADERS(libutil.h util.h pty.h)
AC_CHECK_LIB(util, openpty, [AC_DEFINE_UNQUOTED(HAVE_OPENPTY, 1, [Define if you have openpty in -lutil])])
AC_CHECK_FUNCS(openpty initgroups setgroups getgroups grantpt setpriority getpt unlockpt ptsname)

AH_VERBATIM(_OPENPTY,
[
/*
 * Steven Schultz <sms at to.gd-es.com> tells us :
 * BSD/OS 4.2 doesn't have a prototype for openpty in its system header files
 */
#ifdef __bsdi__
__BEGIN_DECLS
int openpty(int *, int *, char *, struct termios *, struct winsize *);
__END_DECLS
#endif
])

dnl irix pty stuff
AC_CHECK_FUNCS(_getpty)

AC_MSG_CHECKING([for struct ucred])
AC_CACHE_VAL(kde_cv_have_struct_ucred,
[
  AC_TRY_COMPILE(
  [
    #include <sys/socket.h>
  ],
  [
    struct ucred cred;
  ], kde_cv_have_struct_ucred=yes,
  kde_cv_have_struct_ucred=no)
])

AC_MSG_RESULT($kde_cv_have_struct_ucred)
if test "$kde_cv_have_struct_ucred" = yes; then
   AC_DEFINE(HAVE_STRUCT_UCRED,1, [Define if struct ucred is present from sys/socket.h])
fi
AC_CHECK_FUNCS(getpeereid)
