ttyname(3)

端末名を返す · man3 · 日本語

TTYNAME(3) Linux Programmer's Manual TTYNAME(3)

ttyname, ttyname_r - 端末名を返す

#include <unistd.h>
char *ttyname(int fd);
int ttyname_r(int fd, char *buf, size_t buflen);

ttyname() 関数は、ファイルディスクリプター fd がオープンしている端末デバイスの NULL 終端されたパス名へのポインターを返す。 エラーが起きたならば NULL を返す (たとえば、fd が端末を参照していないとき)。 返り値は静的データを指しているので、次の呼び出しで上書きされる可能性がある。 ttyname_r() 関数は、このパス名を長さ buflen のバッファー buf に格納する。

ttyname() 関数は、成功時はパス名へのポインターを返す。 エラー時は NULL を返し、 errno が適切に設定される。 ttyname_r() 関数は、成功時には 0 を返し、エラー時にはエラー番号を返す。

ファイルディスクリプターが不正。
fd refers to a slave pseudoterminal device but the corresponding pathname could not be found (see NOTES).
fd が端末デバイスを参照していない。
(ttyname_r()) buflen がパス名を格納するには短すぎる。

この節で使用されている用語の説明については、 attributes(7)EN を参照。

インターフェース 属性 値
ttyname() Thread safety MT-Unsafe race:ttyname
ttyname_r() Thread safety MT-Safe

POSIX.1-2001, POSIX.1-2008, 4.2BSD.

A process that keeps a file descriptor that refers to a pts(4) device open when switching to another mount namespace that uses a different /dev/ptmx instance may still accidentally find that a device path of the same name for that file descriptor exists. However, this device path refers to a different device and thus can't be used to access the device that the file descriptor refers to. Calling ttyname() or ttyname_r() on the file descriptor in the new mount namespace will cause these functions to return NULL and set errno to ENODEV.

tty(1), fstat(2), ctermid(3), isatty(3), pts(4)

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

2019-10-10 Linux