1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
'\" et
.TH CTERMID "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
ctermid
\(em generate a pathname for the controlling terminal
.SH SYNOPSIS
.LP
.nf
#include <stdio.h>
.P
char *ctermid(char *\fIs\fP);
.fi
.SH DESCRIPTION
The
\fIctermid\fR()
function shall generate a string that, when used as a pathname,
refers to the current controlling terminal for the current process. If
\fIctermid\fR()
returns a pathname, access to the file is not guaranteed.
.P
The
\fIctermid\fR()
function need not be thread-safe if called with a NULL parameter.
.SH "RETURN VALUE"
If
.IR s
is a null pointer, the string shall be generated in an area that may be
static, the address of which shall be returned. The application shall
not modify the string returned. The returned pointer might be invalidated
or the string content might be overwritten by a subsequent call to
\fIctermid\fR().
The returned pointer might also be invalidated if the calling thread
is terminated.
If
.IR s
is not a null pointer,
.IR s
is assumed to point to a character array of at least L_ctermid bytes;
the string is placed in this array and the value of
.IR s
shall be returned. The symbolic constant L_ctermid is defined in
.IR <stdio.h> ,
and shall have a value greater than 0.
.P
The
\fIctermid\fR()
function shall return an empty string if the pathname that would refer
to the controlling terminal cannot be determined, or if the function is
unsuccessful.
.SH ERRORS
No errors are defined.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
.SS "Determining the Controlling Terminal for the Current Process"
.P
The following example returns a pointer to a string that identifies the
controlling terminal for the current process. The pathname for the
terminal is stored in the array pointed to by the
.IR ptr
argument, which has a size of L_ctermid bytes, as indicated by the
.IR term
argument.
.sp
.RS 4
.nf
#include <stdio.h>
\&...
char term[L_ctermid];
char *ptr;
.P
ptr = ctermid(term);
.fi
.P
.RE
.SH "APPLICATION USAGE"
The difference between
\fIctermid\fR()
and
\fIttyname\fR()
is that
\fIttyname\fR()
must be handed a file descriptor and return a path of the terminal
associated with that file descriptor, while
\fIctermid\fR()
returns a string (such as
.BR \(dq/dev/tty\(dq )
that refers to the current controlling terminal if used as a
pathname.
.SH RATIONALE
L_ctermid
must be defined appropriately for a given implementation and must be
greater than zero so that array declarations using it are accepted by
the compiler. The value includes the terminating null byte.
.P
Conforming applications that use multiple threads cannot call
\fIctermid\fR()
with NULL as the parameter. If
.IR s
is not NULL, the
\fIctermid\fR()
function generates a string that, when used as a pathname, refers to
the current controlling terminal for the current process. If
.IR s
is NULL, the return value of
\fIctermid\fR()
is undefined.
.P
There is no additional burden on the programmer\(emchanging to use a
hypothetical thread-safe version of
\fIctermid\fR()
along with allocating a buffer is more of a burden than merely
allocating a buffer. Application code should not assume that the
returned string is short, as some implementations have more than two
pathname components before reaching a logical device name.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIttyname\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<stdio.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|