dnl CF__GRANTPT_BODY version: 5 updated: 2020/03/10 18:53:47
dnl ----------------
dnl Body for workability check of grantpt.
define([CF__GRANTPT_BODY],[
	int code = 0;
	int rc;
	int pty;
	int tty;
	char *slave;
	struct termios tio;

	(void)tio;
	signal(SIGALRM, my_timeout);

	if (alarm(2) == 9)
		failed(9);
	else if ((pty = posix_openpt(O_RDWR)) < 0)
		failed(1);
	else if ((rc = grantpt(pty)) < 0)
		failed(2);
	else if ((rc = unlockpt(pty)) < 0)
		failed(3);
	else if ((slave = ptsname(pty)) == 0)
		failed(4);
#if (CONFTEST == 3) || defined(CONFTEST_isatty)
	else if (!isatty(pty))
		failed(4);
#endif
#if CONFTEST >= 4
    else if ((rc = tcgetattr(pty, &tio)) < 0)
		failed(20);
    else if ((rc = tcsetattr(pty, TCSAFLUSH, &tio)) < 0)
		failed(21);
#endif
	/* BSD posix_openpt does not treat pty as a terminal until slave is opened.
	 * Linux does treat it that way.
	 */
	else if ((tty = open(slave, O_RDWR)) < 0)
		failed(5);
#ifdef CONFTEST
#ifdef I_PUSH
#if (CONFTEST == 0) || defined(CONFTEST_ptem)
    else if ((rc = ioctl(tty, I_PUSH, "ptem")) < 0)
		failed(10);
#endif
#if (CONFTEST == 1) || defined(CONFTEST_ldterm)
    else if ((rc = ioctl(tty, I_PUSH, "ldterm")) < 0)
		failed(11);
#endif
#if (CONFTEST == 2) || defined(CONFTEST_ttcompat)
    else if ((rc = ioctl(tty, I_PUSH, "ttcompat")) < 0)
		failed(12);
#endif
#endif /* I_PUSH */
#if CONFTEST >= 5
    else if ((rc = tcgetattr(tty, &tio)) < 0)
		failed(30);
    else if ((rc = tcsetattr(tty, TCSAFLUSH, &tio)) < 0)
		failed(31);
#endif
#endif /* CONFTEST */

	${cf_cv_main_return:-return}(code);
])
