home *** CD-ROM | disk | FTP | other *** search
- #include "ptyx.h"
- #include <stdio.h>
-
- extern char *ttydev;
- extern char *ptydev;
-
- get_pty (pty)
- int *pty;
- {
- static int devindex, letter = 0;
-
-
- ttydev = (char *) malloc (strlen (TTYDEV) + 1);
- ptydev = (char *) malloc (strlen (PTYDEV) + 1);
- if (!ttydev || !ptydev) {
- fprintf (stderr,
- "cons: unable to allocate memory for ttydev or ptydev\n");
- return (1);
- }
- strcpy (ttydev, TTYDEV);
- strcpy (ptydev, PTYDEV);
-
-
- 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];
- if ((*pty = open (ptydev, O_RDWR)) >= 0) {
- /* We need to set things up for our next entry
- * into this function!
- */
- (void) devindex++;
- return(0);
- }
- devindex++;
- }
- devindex = 0;
- (void) letter++;
- }
- /* We were unable to allocate a pty master! Return an error
- * condition and let our caller terminate cleanly.
- */
- return(1);
- }
-