Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > T


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


ttyname(), ttyname_r(), isatty() — find name of a terminal


#include <unistd.h>

char *ttyname(int fildes);

int ttyname_r(int fildes, char *buffer, size_t buflen);

int isatty(int fildes);


ttyname() returns a pointer to a string containing the null-terminated path name of the terminal device associated with file descriptor fildes.

isatty() returns 1 if fildes is associated with a terminal device, 0 otherwise.

Reentrant Interfaces

ttyname_r() returns the result string in the supplied buffer. The buffer is buflen characters long and should have space for the name and the terminating null character. The maximum length of the terminal name is TTY_NAME_MAX.


ttyname() returns a NULL pointer if fildes does not describe a terminal device in directory /dev. ttyname_r() returns a zero upon success and an error number upon failure.


isatty() and ttyname() fail if any of the following conditions are encountered:


The fildes argument is invalid.


An inappropriate I/O control operation has been attempted.


The return value for ttyname() points to static data whose content is overwritten by each call.


For streams ptys, ttyname() and isatty() do not consider master ptys to be tty devices. It should also be noted that ttyname() returns a pointer to the master pty name for all master pty devices. This is a result of device files being linked together.

Users of ttyname_r() should also note that the prototype of this function has changed in this release for conformance with the POSIX.1c Threads standard. The old prototype of ttyname_r() is supported for compatibility with existing DCE applications only.


/dev/* /dev/pty/*


ttyname(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

ttyname_r(): POSIX.1c

isatty(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.