2 * TNET A server program for MINIX which implements the TCP/IP
3 * suite of networking protocols. It is based on the
4 * TCP/IP code written by Phil Karn et al, as found in
5 * his NET package for Packet Radio communications.
7 * Handle the allocation of a PTY.
9 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
11 #include <sys/types.h>
21 #define DEV_DIR "/dev"
24 * Allocate a PTY, by trying to open one repeatedly,
25 * until all PTY channels are done. If at that point
26 * no PTY is found, go into panic mode :-(
28 int get_pty(pty_fdp
, tty_namep
)
32 char buff
[128], temp
[128];
35 static char tty_name
[128];
37 for(i
= 'p'; i
< 'w'; i
++) {
40 sprintf(buff
, "%s/pty%c%c",
41 DEV_DIR
, i
, (j
< 10) ? j
+ '0' : j
+ 'a' - 10);
44 (void) write(2, "Testing: ", 9);
45 (void) write(2, buff
, strlen(buff
));
46 (void) write(2, "...: ", 5);
49 pty_fd
= open(buff
, O_RDWR
);
51 if (pty_fd
< 0) sprintf(temp
, "error %d\r\n", errno
);
52 else sprintf(temp
, "OK\r\n");
53 (void) write(2, temp
, strlen(temp
));
56 if (pty_fd
>= 0) break;
62 /* Did we find one? */
65 if (pty_fd
< 0) return(-1);
68 sprintf(temp
, "File %s, desc %d\n", buff
, pty_fd
);
69 (void) write(1, temp
, strlen(temp
));
72 sprintf(tty_name
, "%s/tty%c%c", DEV_DIR
,
73 i
, (j
< 10) ? j
+ '0' : j
+ 'a' - 10);
76 *tty_namep
= tty_name
;