1AC_DEFUN([AX_CHECK_PTYFUNCS], [
2    dnl This is a workaround for a bug in Debian package
3    dnl libbsd-dev-0.3.0-1. Once we no longer support that
4    dnl package we can remove the addition of -Werror to
5    dnl CPPFLAGS.
6    AX_SAVEVAR_SAVE(CPPFLAGS)
7    CPPFLAGS="$CPPFLAGS -Werror"
8    AC_CHECK_HEADER([libutil.h],[
9      AC_DEFINE([INCLUDE_LIBUTIL_H],[<libutil.h>],[libutil header file name])
10    ])
11    AX_SAVEVAR_RESTORE(CPPFLAGS)
12    AC_CACHE_CHECK([for openpty et al], [ax_cv_ptyfuncs_libs], [
13        for ax_cv_ptyfuncs_libs in -lutil "" NOT_FOUND; do
14            if test "x$ax_cv_ptyfuncs_libs" = "xNOT_FOUND"; then
15                AC_MSG_FAILURE([Unable to find library for openpty and login_tty])
16            fi
17            AX_SAVEVAR_SAVE(LIBS)
18            LIBS="$LIBS $ax_cv_ptyfuncs_libs"
19            AC_LINK_IFELSE([AC_LANG_SOURCE([
20#ifdef INCLUDE_LIBUTIL_H
21#include INCLUDE_LIBUTIL_H
22#endif
23int main(void) {
24  openpty(0,0,0,0,0);
25  login_tty(0);
26}
27])],[
28                break
29            ],[])
30            AX_SAVEVAR_RESTORE(LIBS)
31        done
32    ])
33    PTYFUNCS_LIBS="$ax_cv_ptyfuncs_libs"
34    AC_SUBST(PTYFUNCS_LIBS)
35])
36