Platform Survey¶
I don't believe these interfaces appear in any published UNIX standard. They do, however, appear on OpenBSD, FreeBSD, Mac OS X, Oracle Solaris, and Linux systems:
int openpty(int *, int *, char *, struct termios *, struct winsize *);
int forkpty(int *, int *, char *, struct termios *, struct winsize *);
int login_tty(int);
OpenBSD offers some additional interfaces in this family:
int getptmfd(void);
int fdopenpty(int, int *, int *, char *, struct termios *, struct winsize *);
int fdforkpty(int, int *, char *, struct termios *, struct winsize *);
They seem somewhat predicated on having a file descriptor that represents a management device. What we have is, instead, a cloning device: you open it and the act of opening it is what gets you a pseudo terminal pair. As it isn't exactly clear how these would work for us, and they don't seem to be widely available otherwise, so I am going to leave them out.
These routines will go directly in the C library. The header situation is something of a mess; each platform has made a slightly different choice, and we don't have the pty.h
header that Linux (and only Linux) is using here. What we do have is termios.h
, which you will need for struct termios
anyway, so that seems as good a place as any -- and is the choice that Oracle have made as well.