The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


ctermid - generate a pathname for controlling terminal


#include <stdio.h>

char *ctermid(char *s);


The ctermid() function generates a string that, when used as a pathname, refers to the current controlling terminal for the current process. If ctermid() returns a pathname, access to the file is not guaranteed.

If the application uses any of the _POSIX_THREAD_SAFE_FUNCTIONS or _POSIX_THREADS interfaces, the ctermid() function must be called with a non-NULL parameter.


If s is a null pointer, the string is generated in an area that may be static (and therefore may be overwritten by each call), the address of which is returned. Otherwise s is assumed to point to a character array of at least {L_ctermid} bytes; the string is placed in this array and the value of s is returned. The symbolic constant {L_ctermid} is defined in <stdio.h>, and will have a value greater than 0.

The ctermid() function will return an empty string if the pathname that would refer to the controlling terminal cannot be determined, or if the function is unsuccessful.


No errors are defined.




The difference between ctermid() and ttyname() is that ttyname() must be handed a file descriptor and returns a path of the terminal associated with that file descriptor, while ctermid() returns a string (such as /dev/tty) that will refer to the current controlling terminal if used as a pathname.




ttyname(), <stdio.h>.


Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]