How can you tell whether an fd refers to inside or the outside of a pseudoterminal? How can you tell whether an fd refers to inside or the outside of a pseudoterminal? unix unix

How can you tell whether an fd refers to inside or the outside of a pseudoterminal?


According to ptsname manual:

char *ptsname(int fd);

The ptsname() function returns the name of the slave pseudoterminal device corresponding to the master referred to by fd.

And it will fail with ENOTTY if

fd does not refer to a pseudoterminal master device.

So you can first call isatty() and then ptsname().

And ptsname() is

CONFORMING TO POSIX.1-2001, POSIX.1-2008.