DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

ttyname(S)


ttyname, isatty -- get name of a terminal

Syntax

cc . . . -lc

#include <unistd.h>

char *ttyname(int fildes);

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

int isatty(int fildes);

Description

The ttyname routine returns a pointer to a string containing the null-terminated pathname of the terminal device associated with file descriptor fildes. The return value may point to static data whose content is overwritten by each call.

The ttyname_r routine stores in the string pointed to by buffer (up to buflen bytes) the null-terminated path name of the terminal device associated with the file descriptor fildes.

The isatty routine tests whether fildes, an open file descriptor, is associated with a terminal device. isatty returns 1 if fildes is associated with a terminal device, 0 otherwise with errno set.

Files

/dev/*

Diagnostics

On unsuccessful completion ttyname and ttyname_r returns a null pointer if fildes does not describe a terminal device in directory /dev and errno is set.

If either isatty or ttyname fail, then errno contains one of:


[EBADF]
The fildes argument is not a valid file descriptor.

[ENOTTY]
The fildes argument does not refer to a terminal device.

If ttyname_r fails NULL is returned and sets errno:


[ERANGE]
buflen is smaller than the length of the string to be returned.

Note

The return value points to static data whose content is overwritten by each call.

Differences between versions

The isatty( ) routine in current releases uses the default mode that conforms to the standard. If you require compatibility with older releases, specify cc -a ods30 when compiling.

Standards conformance

isatty and ttyname are conformant with:

X/Open Portability Guide, Issue 3, 1989 ;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2) ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003