Subject: Re: trouble using a PTY
From: egor duda <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Sun, 3 Nov 2002 17:47:53 +0300

Hi!

Sunday, 03 November, 2002 [email-masked] [email-masked] wrote:

Fcc> I'm trying to run some very simple code that uses ptys. The
Fcc> code is from W. Richard Stevens APUE book. The only change is

This code is non-portable. The names of ptys are system-specific, and
not guaranteed to be named /dev/ptyXY.

On cygwin, master side of pseudo tty can be opened via
open("/dev/ptym",...). Then you can use grantpt(), unlockpt() and
ptsname() functions to access a slave side of pty.

Unfortunately, its not very portable, either. Proposed portable
interface to open master side of pseudo tty is posix_openpt(), but it
haven't been implemented on cygwin yet. "Patches are gratefully
accepted" (tm).

BTW, implementing this function looks like an easy prey for those who
wish to contribute something to cygwin, but afraid of complexities of
cygwin internals.

Fcc> the printf you see below. In this routine:
Fcc> int
Fcc> ptym_open(char *pts_name)
Fcc> {
Fcc>         int             fdm;
Fcc>         char    *ptr1, *ptr2;
Fcc>         strcpy(pts_name, "/dev/ptyXY");
Fcc>           /* array index: 0123456789 (for references in following code) */
Fcc>         for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
Fcc>                 pts_name[8] = *ptr1;
Fcc>                 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
Fcc>                         pts_name[9] = *ptr2;
Fcc>                         /* try to open master */
Fcc>                         if ( (fdm = open(pts_name, O_RDWR)) < 0) {
Fcc> printf ("ptym_open, open returned errno of: %d, pts_name=%s\n",
Fcc> errno,pts_name);
Fcc>                                 if (errno == ENOENT)    /* different from
Fcc> EIO */
Fcc>                                         return(-1);   /*out of pty devices
Fcc> */
Fcc>                                 else
Fcc>                                         continue;    /*try next pty device
Fcc> */
Fcc>                        }
Fcc>                         pts_name[5] = 't';      /* change "pty" to "tty" */
Fcc>                         return(fdm);            /* got it, return fd of
Fcc> master */
Fcc>                 }
Fcc>         }
Fcc>         printf ("pty, at end, errno is: %d\n", errno);
Fcc>         return(-1);             /* out of pty devices */
Fcc> }
Fcc> the first call to open() fails, and the printf produces:
Fcc>      ptym_open, open returned errno of: 2, pts_name=/dev/ptyp0
Fcc> As far as I can deduce by reading cygwin docs and mailing list archives,
Fcc> PTYs would be expected to work.
Fcc> I'd appreciate it if someone could point me in the right direction here.
Fcc> attached is output of "cygcheck -s"

Egor.            mailto:[email-masked] ICQ 5165414 FidoNet 2:5020/496.19

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/