1CTERMID(3P)                POSIX Programmer's Manual               CTERMID(3P)
2
3
4

PROLOG

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
11

NAME

13       ctermid — generate a pathname for the controlling terminal
14

SYNOPSIS

16       #include <stdio.h>
17
18       char *ctermid(char *s);
19

DESCRIPTION

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       The  ctermid()  function  need not be thread-safe if called with a NULL
27       parameter.
28

RETURN VALUE

30       If s is a null pointer, the string shall be generated in an  area  that
31       may  be static, the address of which shall be returned. The application
32       shall not modify the string returned. The  returned  pointer  might  be
33       invalidated  or the string content might be overwritten by a subsequent
34       call to ctermid().  If s is not a null pointer, s is assumed  to  point
35       to  a character array of at least L_ctermid bytes; the string is placed
36       in this array and the value of s shall be returned. The  symbolic  con‐
37       stant L_ctermid is defined in <stdio.h>, and shall have a value greater
38       than 0.
39
40       The ctermid() function shall return an empty  string  if  the  pathname
41       that  would  refer to the controlling terminal cannot be determined, or
42       if the function is unsuccessful.
43

ERRORS

45       No errors are defined.
46
47       The following sections are informative.
48

EXAMPLES

50   Determining the Controlling Terminal for the Current Process
51       The following example returns a pointer to a string that identifies the
52       controlling terminal for the current process. The pathname for the ter‐
53       minal is stored in the array pointed to by the ptr argument, which  has
54       a size of L_ctermid bytes, as indicated by the term argument.
55
56           #include <stdio.h>
57           ...
58           char term[L_ctermid];
59           char *ptr;
60
61           ptr = ctermid(term);
62

APPLICATION USAGE

64       The  difference  between ctermid() and ttyname() is that ttyname() must
65       be handed a file descriptor and return a path of the  terminal  associ‐
66       ated  with that file descriptor, while ctermid() returns a string (such
67       as "/dev/tty") that refers to the current controlling terminal if  used
68       as a pathname.
69

RATIONALE

71       L_ctermid  must be defined appropriately for a given implementation and
72       must be greater than zero so  that  array  declarations  using  it  are
73       accepted by the compiler. The value includes the terminating null byte.
74
75       Conforming applications that use multiple threads cannot call ctermid()
76       with NULL as the parameter. If s is not NULL,  the  ctermid()  function
77       generates a string that, when used as a pathname, refers to the current
78       controlling terminal for the current process. If s is NULL, the  return
79       value of ctermid() is undefined.
80
81       There is no additional burden on the programmer—changing to use a hypo‐
82       thetical thread-safe version of ctermid() along with allocating a  buf‐
83       fer  is  more  of a burden than merely allocating a buffer. Application
84       code should not assume that the  returned  string  is  short,  as  some
85       implementations  have more than two pathname components before reaching
86       a logical device name.
87

FUTURE DIRECTIONS

89       None.
90

SEE ALSO

92       ttyname()
93
94       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
95
97       Portions of this text are reprinted and reproduced in  electronic  form
98       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
99       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
100       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
101       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
102       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) 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.unix.org/online.html .
107
108       Any  typographical  or  formatting  errors that appear in this page are
109       most likely to have been introduced during the conversion of the source
110       files  to  man page format. To report such errors, see https://www.ker
111       nel.org/doc/man-pages/reporting_bugs.html .
112
113
114
115IEEE/The Open Group                  2013                          CTERMID(3P)
Impressum