1CTERMID(3P) POSIX Programmer's Manual CTERMID(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 ctermid - generate a pathname for the controlling terminal
13
15 #include <stdio.h>
16
17 char *ctermid(char *s);
18
19
21 The ctermid() function shall generate a string that, when used as a
22 pathname, refers to the current controlling terminal for the current
23 process. If ctermid() returns a pathname, access to the file is not
24 guaranteed.
25
26 If the application uses any of the _POSIX_THREAD_SAFE_FUNCTIONS or
27 _POSIX_THREADS functions, it shall ensure that the ctermid() function
28 is called with a non-NULL parameter.
29
31 If s is a null pointer, the string shall be generated in an area that
32 may be static (and therefore may be overwritten by each call), the
33 address of which shall be returned. Otherwise, s is assumed to point to
34 a character array of at least L_ctermid bytes; the string is placed in
35 this array and the value of s shall be returned. The symbolic constant
36 L_ctermid is defined in <stdio.h>, and shall have a value greater than
37 0.
38
39 The ctermid() function shall return an empty string if the pathname
40 that would refer to the controlling terminal cannot be determined, or
41 if the function is unsuccessful.
42
44 No errors are defined.
45
46 The following sections are informative.
47
49 Determining the Controlling Terminal for the Current Process
50 The following example returns a pointer to a string that identifies the
51 controlling terminal for the current process. The pathname for the ter‐
52 minal is stored in the array pointed to by the ptr argument, which has
53 a size of L_ctermid bytes, as indicated by the term argument.
54
55
56 #include <stdio.h>
57 ...
58 char term[L_ctermid];
59 char *ptr;
60
61
62 ptr = ctermid(term);
63
65 The difference between ctermid() and ttyname() is that ttyname() must
66 be handed a file descriptor and return a path of the terminal associ‐
67 ated with that file descriptor, while ctermid() returns a string (such
68 as "/dev/tty" ) that refers to the current controlling terminal if used
69 as a pathname.
70
72 L_ctermid must be defined appropriately for a given implementation and
73 must be greater than zero so that array declarations using it are
74 accepted by the compiler. The value includes the terminating null byte.
75
76 Conforming applications that use threads cannot call ctermid() with
77 NULL as the parameter if either _POSIX_THREAD_SAFE_FUNCTIONS or
78 _POSIX_THREADS is defined. If s is not NULL, the ctermid() function
79 generates a string that, when used as a pathname, refers to the current
80 controlling terminal for the current process. If s is NULL, the return
81 value of ctermid() is undefined.
82
83 There is no additional burden on the programmer-changing to use a hypo‐
84 thetical thread-safe version of ctermid() along with allocating a buf‐
85 fer is more of a burden than merely allocating a buffer. Application
86 code should not assume that the returned string is short, as some
87 implementations have more than two pathname components before reaching
88 a logical device name.
89
91 None.
92
94 ttyname(), the Base Definitions volume of IEEE Std 1003.1-2001,
95 <stdio.h>
96
98 Portions of this text are reprinted and reproduced in electronic form
99 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
100 -- Portable Operating System Interface (POSIX), The Open Group Base
101 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
102 Electrical and Electronics Engineers, Inc and The Open Group. In the
103 event of any discrepancy between this version and the original IEEE and
104 The Open Group Standard, the original IEEE and The Open Group Standard
105 is the referee document. The original Standard can be obtained online
106 at http://www.opengroup.org/unix/online.html .
107
108
109
110IEEE/The Open Group 2003 CTERMID(3P)