1ttyname(3)                 Library Functions Manual                 ttyname(3)
2
3
4

NAME

6       ttyname, ttyname_r - return name of a terminal
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <unistd.h>
13
14       char *ttyname(int fd);
15       int ttyname_r(int fd, char buf[.buflen], size_t buflen);
16

DESCRIPTION

18       The  function  ttyname() returns a pointer to the null-terminated path‐
19       name of the terminal device that is open on the file descriptor fd,  or
20       NULL on error (for example, if fd is not connected to a terminal).  The
21       return value may point to static data, possibly overwritten by the next
22       call.   The function ttyname_r() stores this pathname in the buffer buf
23       of length buflen.
24

RETURN VALUE

26       The function ttyname() returns a pointer to a pathname on success.   On
27       error,  NULL  is returned, and errno is set to indicate the error.  The
28       function ttyname_r() returns 0 on success, and an error number upon er‐
29       ror.
30

ERRORS

32       EBADF  Bad file descriptor.
33
34       ENODEV fd refers to a slave pseudoterminal device but the corresponding
35              pathname could not be found (see NOTES).
36
37       ENOTTY fd does not refer to a terminal device.
38
39       ERANGE (ttyname_r()) buflen was too small to allow  storing  the  path‐
40              name.
41

ATTRIBUTES

43       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
44       tributes(7).
45
46       ┌─────────────────────────────┬───────────────┬────────────────────────┐
47Interface                    Attribute     Value                  
48       ├─────────────────────────────┼───────────────┼────────────────────────┤
49ttyname()                    │ Thread safety │ MT-Unsafe race:ttyname │
50       ├─────────────────────────────┼───────────────┼────────────────────────┤
51ttyname_r()                  │ Thread safety │ MT-Safe                │
52       └─────────────────────────────┴───────────────┴────────────────────────┘
53

STANDARDS

55       POSIX.1-2008.
56

HISTORY

58       POSIX.1-2001, 4.2BSD.
59

NOTES

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

SEE ALSO

71       tty(1), fstat(2), ctermid(3), isatty(3), pts(4)
72
73
74
75Linux man-pages 6.04              2023-03-30                        ttyname(3)
Impressum