static char line[] = "/dev/ptyXX";
char line[11];
openpty(amaster, aslave, name, termp, winp)	int *amaster, *aslave;	char *name;	struct termios *termp;	struct winsize *winp;{	static char line[] = "/dev/ptyXX";	register const char *cp1, *cp2;	register int master, slave, ttygid;	size_t buflen = sysconf (_SC_GETGR_R_SIZE_MAX);	char buffer[buflen];	struct group grbuffer;	struct group *gr;	if (getgrnam_r("tty", &grbuffer, buffer, buflen, &gr) >= 0)		ttygid = gr->gr_gid;	else		ttygid = -1;	for (cp1 = "pqrs"; *cp1; cp1++) {		line[8] = *cp1;		for (cp2 = "0123456789abcdef"; *cp2; cp2++) {			line[9] = *cp2;			if ((master = open(line, O_RDWR, 0)) == -1) {				if (errno == ENOENT)					return (-1);	/* out of ptys */			} else {				line[5] = 't';				(void) chown(line, getuid(), ttygid);				(void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);				(void) revoke(line);				if ((slave = open(line, O_RDWR, 0)) != -1) {					*amaster = master;					*aslave = slave;					if (name)						strcpy(name, line);					if (termp)						(void) tcsetattr(slave,							TCSAFLUSH, termp);					if (winp)						(void) ioctl(slave, TIOCSWINSZ,							(char *)winp);					return (0);				}				(void) close(master);				line[5] = 'p';			}		}	}	__set_errno (ENOENT);	/* out of ptys */	return (-1);}