pty_search(pty) int *pty;
pty_search(int *pty)
pty_search(pty)    int *pty;{    static int devindex, letter = 0;#if defined(CRAY)    for (; devindex < MAXPTTYS; devindex++) {	sprintf (ttydev, TTYFORMAT, devindex);	sprintf (ptydev, PTYFORMAT, devindex);	if ((*pty = open (ptydev, O_RDWR)) >= 0) {	    /* We need to set things up for our next entry	     * into this function!	     */	    (void) devindex++;	    return 0;	}    }#else /* CRAY */    while (PTYCHAR1[letter]) {	ttydev [strlen(ttydev) - 2]  = ptydev [strlen(ptydev) - 2] =	    PTYCHAR1 [letter];	while (PTYCHAR2[devindex]) {	    ttydev [strlen(ttydev) - 1] = ptydev [strlen(ptydev) - 1] =		PTYCHAR2 [devindex];	    /* for next time around loop or next entry to this function */	    devindex++;	    if ((*pty = open (ptydev, O_RDWR)) >= 0) {#ifdef sun		/* Need to check the process group of the pty.		 * If it exists, then the slave pty is in use,		 * and we need to get another one.		 */		int pgrp_rtn;		if (ioctl(*pty, TIOCGPGRP, &pgrp_rtn) == 0 || errno != EIO) {		    close(*pty);		    continue;		}#endif /* sun */		return 0;	    }	}	devindex = 0;	(void) letter++;    }#endif /* CRAY else */    /*     * We were unable to allocate a pty master!  Return an error     * condition and let our caller terminate cleanly.     */    return 1;}