Hi,
When I opened a pty pair in SunOS 4.1.1 for Sun3, the master tty
is not recognized as a tty, thus causing standard output buffering
problem. The result of running the following program is:
Master is not a tty
Slave is a tty
I tried the same program again under other 4.3BSD dervied Unix'es,
and they give me instead:
Master is a tty
Slave is a tty
Is this a bug with SunOS, or do I need to do something special
in making the master pty a tty as well?
Thanks for your help.
XXXXXXXXXXXXXXXXXXXXXXXX CUT HERE XXXXXXXXXXXXXXXXXXXXXXXX
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#define TTY_NAME "/dev/TtyXY"
#define TTY_POS_T 5
#define TTY_POS_X 8
#define TTY_POS_Y 9
/* Open a master pty and the corresponding slave tty. Return 0 if */
/* OK, or -1 if cannot open a valid pty pair */
int
OpenPty(int *master, int *slave)
{
char ttyname[] = TTY_NAME;
char xnames[] = "pqrs";
char ynames[] = "0123456789abcdef";
int x, y;
for (x = 0; xnames[x]; x++) {
ttyname[TTY_POS_X] = xnames[x];
for (y = 0; ynames[y]; y++) {
ttyname[TTY_POS_Y] = ynames[y];
/* Open Master (control) PTY */
ttyname[TTY_POS_T] = 'p';
if ((*master = open(ttyname, O_WRONLY)) < 0)
continue;
/* Open Slave PTY */
ttyname[TTY_POS_T] = 't';
if ((*slave = open(ttyname, O_RDONLY)) < 0)
(void) close(*master);
else
return 0;
}
}
return -1;
intQuote:}
main(int argc, char *argv[])
{
int master, slave;
if (OpenPty(&master, &slave) < 0) {
fputs("Failure to open pty\n", stderr);
exit(-1);
}
if (isatty(master))
puts("Master is a tty");
else
puts("Master is not a tty");
if (isatty(slave))
puts("Slave is a tty");
else
puts("Slave is not a tty");
exit(0);
Quote:}