1TTYNAME(P) POSIX Programmer's Manual TTYNAME(P)
2
3
4
6 ttyname, ttyname_r - find the pathname of a terminal
7
9 #include <unistd.h>
10
11 char *ttyname(int fildes);
12
13
14 int ttyname_r(int fildes, char *name, size_t namesize);
15
16
18 The ttyname() function shall return a pointer to a string containing a
19 null-terminated pathname of the terminal associated with file descrip‐
20 tor fildes. The return value may point to static data whose content is
21 overwritten by each call.
22
23 The ttyname() function need not be reentrant. A function that is not
24 required to be reentrant is not required to be thread-safe.
25
26 The ttyname_r() function shall store the null-terminated pathname of
27 the terminal associated with the file descriptor fildes in the charac‐
28 ter array referenced by name. The array is namesize characters long and
29 should have space for the name and the terminating null character. The
30 maximum length of the terminal name shall be {TTY_NAME_MAX}.
31
33 Upon successful completion, ttyname() shall return a pointer to a
34 string. Otherwise, a null pointer shall be returned and errno set to
35 indicate the error.
36
37 If successful, the ttyname_r() function shall return zero. Otherwise,
38 an error number shall be returned to indicate the error.
39
41 The ttyname() function may fail if:
42
43 EBADF The fildes argument is not a valid file descriptor.
44
45 ENOTTY The fildes argument does not refer to a terminal.
46
47
48 The ttyname_r() function may fail if:
49
50 EBADF The fildes argument is not a valid file descriptor.
51
52 ENOTTY The fildes argument does not refer to a terminal.
53
54 ERANGE The value of namesize is smaller than the length of the string
55 to be returned including the terminating null character.
56
57
58 The following sections are informative.
59
61 None.
62
64 None.
65
67 The term ``terminal'' is used instead of the historical term ``terminal
68 device'' in order to avoid a reference to an undefined term.
69
70 The thread-safe version places the terminal name in a user-supplied
71 buffer and returns a non-zero value if it fails. The non-thread-safe
72 version may return the name in a static data area that may be overwrit‐
73 ten by each call.
74
76 None.
77
79 The Base Definitions volume of IEEE Std 1003.1-2001, <unistd.h>
80
82 Portions of this text are reprinted and reproduced in electronic form
83 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
84 -- Portable Operating System Interface (POSIX), The Open Group Base
85 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
86 Electrical and Electronics Engineers, Inc and The Open Group. In the
87 event of any discrepancy between this version and the original IEEE and
88 The Open Group Standard, the original IEEE and The Open Group Standard
89 is the referee document. The original Standard can be obtained online
90 at http://www.opengroup.org/unix/online.html .
91
92
93
94IEEE/The Open Group 2003 TTYNAME(P)