[Previous] [Contents] [Index] [Next]

ttyname()

Get a fully qualified pathname for a file

Synopsis:

#include <unistd.h>

char *ttyname( int fildes );

Library:

libc

Description:

The ttyname() function returns a pointer to a static buffer that contains a fully qualified pathname associated with the file associated with fildes.

Returns:

A pointer to the pathname for fildes, or NULL if an error occurred (errno is set).

Errors:

EBADF
The fildes argument is invalid.
ENOSYS
The ttyname() function isn't implemented for the filesystem specified by filedes.
ENOTTY
Not a tty.

Examples:

/*
 * The following program prints out the name
 * of the terminal associated with stdin.
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main( void )
{
    if( isatty( 0 ) ) {
       printf( "%s\n", ttyname( 0 ) );
    } else {
       printf( "\n" );
    }
    return EXIT_SUCCESS;
}

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread No

See also:

ctermid(), errno, setsid(), ttyname_r()


[Previous] [Contents] [Index] [Next]