-dnl dnl Checks if tgetent accepts NULL and will
-dnl dnl allocate its own termcap buffer.
-dnl AC_CACHE_CHECK(if tgetent accepts NULL,
-dnl nmh_cv_func_tgetent_accepts_null,
-dnl [AC_TRY_RUN([main(){int i = tgetent((char*)0,"vt100");exit(!i || i == -1);}],
-dnl nmh_cv_func_tgetent_accepts_null=yes,
-dnl nmh_cv_func_tgetent_accepts_null=no,
-dnl nmh_cv_func_tgetent_accepts_null=no)])
-dnl if test $nmh_cv_func_tgetent_accepts_null = yes; then
-dnl AC_DEFINE(TGETENT_ACCEPTS_NULL)
-dnl fi
+dnl Check if tgetent accepts NULL (and will allocate its own termcap buffer)
+dnl Some termcaps reportedly accept a zero buffer, but then dump core
+dnl in tgetstr().
+dnl Under Cygwin test program crashes but exit code is still 0. So,
+dnl we test for a file that porgram should create
+AH_TEMPLATE([TGETENT_ACCEPTS_NULL],
+[Define to 1 if tgetent() accepts NULL as a buffer.])
+AC_CACHE_CHECK(if tgetent accepts NULL,
+nmh_cv_func_tgetent_accepts_null,
+[AC_TRY_RUN([
+main()
+{
+ char buf[4096];
+ int r1 = tgetent(buf, "vt100");
+ int r2 = tgetent((char*)0,"vt100");
+ if (r1 >= 0 && r1 == r2) {
+ char tbuf[1024], *u;
+ u = tbuf;
+ tgetstr("cl", &u);
+ creat("conftest.tgetent", 0640);
+ }
+ exit((r1 != r2) || r2 == -1);
+}
+],
+ if test -f conftest.tgetent; then
+ nmh_cv_func_tgetent_accepts_null=yes
+ else
+ nmh_cv_func_tgetent_accepts_null=no
+ fi,
+ nmh_cv_func_tgetent_accepts_null=no,
+ nmh_cv_func_tgetent_accepts_null=no)])
+if test x$nmh_cv_func_tgetent_accepts_null = xyes; then
+ AC_DEFINE(TGETENT_ACCEPTS_NULL)
+fi
+AC_CACHE_CHECK(if tgetent returns 0 on success,
+nmh_cv_func_tgetent_zero_success,
+[AC_TRY_RUN([
+main()
+{
+ char buf[4096];
+ int r1 = tgetent(buf, "!@#$%^&*");
+ int r2 = tgetent(buf, "vt100");
+ if (r1 < 0 && r2 == 0) {
+ char tbuf[1024], *u;
+ u = tbuf;
+ tgetstr("cl", &u);
+ creat("conftest.tgetent0", 0640);
+ }
+ exit(r1 == r2);
+}
+],
+ if test -f conftest.tgetent0; then
+ nmh_cv_func_tgetent_zero_success=yes
+ else
+ nmh_cv_func_tgetent_zero_success=no
+ fi,
+ nmh_cv_func_tgetent_zero_success=no,
+ nmh_cv_func_tgetent_zero_success=no)])
+AH_TEMPLATE([TGETENT_SUCCESS],
+[Define to what tgetent() returns on success (0 on HP-UX X/Open curses).])
+if test x$nmh_cv_func_tgetent_zero_success = xyes; then
+ AC_DEFINE(TGETENT_SUCCESS, 0)
+else
+ AC_DEFINE(TGETENT_SUCCESS, 1)
+fi