1ttyname(3C)              Standard C Library Functions              ttyname(3C)
2
3
4

NAME

6       ttyname, ttyname_r - find pathname of a terminal
7

SYNOPSIS

9       #include <unistd.h>
10
11       char *ttyname(int fildes);
12
13
14       char *ttyname_r(int fildes, char *name, int namelen);
15
16
17   Standard conforming
18       cc [ flag...] file ... -D_POSIX_PTHREAD_SEMANTICS [ library ... ]
19
20       int ttyname_r(int fildes, char *name, size_t namesize);
21
22

DESCRIPTION

24       The  ttyname()  function  returns  a pointer to a string containing the
25       null-terminated path name of the terminal device associated  with  file
26       descriptor  fildes.  The  return  value  points to thread-specific data
27       whose content is overwritten by each call from the same thread.
28
29
30       The ttyname_r() function has the same functionality as ttyname() except
31       that  the caller must supply a buffer name with length namelen to store
32       the result; this buffer  must  be  at  least  _POSIX_PATH_MAX  in  size
33       (defined  in  <limits.h>).  The  standard-conforming version (see stan‐
34       dards(5)) of ttyname_r() takes a namesize parameter of type size_t.
35

RETURN VALUES

37       Upon successful completion, ttyname() and ttyname_r() return a  pointer
38       to  a string. Otherwise, a null pointer is returned and errno is set to
39       indicate the error.
40
41
42       The standard-conforming ttyname_r() returns  0  if  successful  or  the
43       error number upon failure.
44

ERRORS

46       The ttyname() and ttyname_r() functions may fail if:
47
48       EBADF     The fildes argument is not a valid file descriptor. This con‐
49                 dition is reported.
50
51
52       ENOTTY    The fildes argument does not refer to a terminal device. This
53                 condition is reported.
54
55
56
57       The ttyname_r() function may fail if:
58
59       ERANGE    The  value  of  namesize  is  smaller  than the length of the
60                 string to be returned including the terminating null  charac‐
61                 ter.
62
63

ATTRIBUTES

65       See attributes(5) for descriptions of the following attributes:
66
67
68
69
70       ┌─────────────────────────────┬─────────────────────────────┐
71       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
72       ├─────────────────────────────┼─────────────────────────────┤
73       │Interface Stability          │Standard                     │
74       ├─────────────────────────────┼─────────────────────────────┤
75       │MT-Level                     │Safe                         │
76       └─────────────────────────────┴─────────────────────────────┘
77

SEE ALSO

79       Intro(3), gettext(3C), setlocale(3C), attributes(5), standards(5)
80

NOTES

82       When  compiling multithreaded applications, see Intro(3), Notes On Mul‐
83       tithreaded Applications.
84
85
86       Messages printed from this function are in the native  language  speci‐
87       fied by the LC_MESSAGES locale category. See setlocale(3C).
88
89
90       The return value of ttyname() points to thread-specific data whose con‐
91       tent is overwritten by each call from the same thread. This function is
92       safe  to use in multithreaded applications, but its use is discouraged.
93       The ttyname_r() function should used instead.
94
95
96       Solaris 2.4 and earlier  releases  provided  definitions  of  the  tty‐
97       name_r() interface as specified in POSIX.1c Draft 6. The final POSIX.1c
98       standard changed the interface as  described  above.  Support  for  the
99       Draft  6  interface is provided for compatibility only and might not be
100       supported in future releases. New applications and libraries should use
101       the standard-conforming interface.
102
103
104
105SunOS 5.11                        31 Mar 2005                      ttyname(3C)
Impressum