home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume7 / xdm / patch1.01 / get_pty.c next >
Encoding:
C/C++ Source or Header  |  1990-06-08  |  1.4 KB  |  48 lines

  1. #include "ptyx.h"
  2. #include <stdio.h>
  3.  
  4. extern char *ttydev;
  5. extern char *ptydev;
  6.  
  7. get_pty (pty)
  8. int *pty;
  9. {
  10.         static int devindex, letter = 0;
  11.  
  12.  
  13.         ttydev = (char *) malloc (strlen (TTYDEV) + 1);
  14.         ptydev = (char *) malloc (strlen (PTYDEV) + 1);
  15.         if (!ttydev || !ptydev) {
  16.             fprintf (stderr,
  17.                      "cons:  unable to allocate memory for ttydev or ptydev\n");
  18.             return (1);
  19.         }
  20.         strcpy (ttydev, TTYDEV);
  21.         strcpy (ptydev, PTYDEV);
  22.  
  23.  
  24.         while (PTYCHAR1[letter]) {
  25.             ttydev [strlen(ttydev) - 2]  = ptydev [strlen(ptydev) - 2] =
  26.                     PTYCHAR1 [letter];
  27.  
  28.             while (PTYCHAR2[devindex]) {
  29.                 ttydev [strlen(ttydev) - 1] = ptydev [strlen(ptydev) - 1] =
  30.                         PTYCHAR2 [devindex];
  31.                 if ((*pty = open (ptydev, O_RDWR)) >= 0) {
  32.                         /* We need to set things up for our next entry
  33.                          * into this function!
  34.                          */
  35.                         (void) devindex++;
  36.                         return(0);
  37.                 }
  38.                 devindex++;
  39.             }
  40.             devindex = 0;
  41.             (void) letter++;
  42.         }
  43.         /* We were unable to allocate a pty master!  Return an error
  44.          * condition and let our caller terminate cleanly.
  45.          */
  46.         return(1);
  47. }
  48.