[Previous] [Contents] [Next]

ctermid()

Generate the pathname of the current controlling terminal

Synopsis:

#include <stdio.h>

char * ctermid( char * s );

Library:

libc

Description:

The ctermid() function generates a string that contains the pathname of the current controlling terminal for the calling process.

If the argument s is NULL, the string is built in a static buffer, and a pointer to the buffer is returned.

If the argument s isn't NULL, then the pathname is placed in that string. This string should be at least L_ctermid characters long (see <stdio.h>).

Returns:

A pointer to the pathname of the controlling terminal; or a pointer to a null string if it's unable to locate the controlling terminal.

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
  printf( "Controlling terminal is %s\n", ctermid( NULL ) );
  return EXIT_SUCCESS;
}

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Read the Caveats

Caveats:

The ctermid() isn't thread-safe if the s argument is NULL.

See also:

setsid(), ttyname()


[Previous] [Contents] [Next]