home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!agate!pasteur!cory.Berkeley.EDU!achoi
- From: achoi@cory.Berkeley.EDU (Andrew Choi)
- Subject: Problem with Pseudo TTY of SunOS 4.1.1 for Sun3
- Message-ID: <1992Sep9.010847.1104@pasteur.Berkeley.EDU>
- Sender: nntp@pasteur.Berkeley.EDU (NNTP Poster)
- Nntp-Posting-Host: cory
- Organization: University of California, at Berkeley
- Distribution: usa
- Date: Wed, 9 Sep 1992 01:08:47 GMT
- Lines: 89
-
- 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;
- }
-
-
- int
- 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);
- }
-
-