CTERMID(3)                 POSIX Programmer's Manual                CTERMID(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       ctermid -- generate a pathname for the controlling terminal

SSYYNNOOPPSSIISS
       #include <stdio.h>

       char *ctermid(char *_s);

DDEESSCCRRIIPPTTIIOONN
       The _c_t_e_r_m_i_d() function shall generate a string that, when used as a
       pathname, refers to the current controlling terminal for the current
       process. If _c_t_e_r_m_i_d() returns a pathname, access to the file is not
       guaranteed.

       The _c_t_e_r_m_i_d() function need not be thread-safe if called with a NULL
       parameter.

RREETTUURRNN VVAALLUUEE
       If _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 _c_t_e_r_m_i_d().  The returned pointer might also be invalidated if
       the calling thread is terminated.  If _s is not a null pointer, _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 _s shall be returned.
       The symbolic constant L_ctermid is defined in _<_s_t_d_i_o_._h_>, and shall have
       a value greater than 0.

       The _c_t_e_r_m_i_d() 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.

EERRRROORRSS
       No errors are defined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   DDeetteerrmmiinniinngg tthhee CCoonnttrroolllliinngg TTeerrmmiinnaall ffoorr tthhee CCuurrrreenntt PPrroocceessss
       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 _p_t_r argument, which
       has a size of L_ctermid bytes, as indicated by the _t_e_r_m argument.


           #include <stdio.h>
           ...
           char term[L_ctermid];
           char *ptr;

           ptr = ctermid(term);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The difference between _c_t_e_r_m_i_d() and _t_t_y_n_a_m_e() is that _t_t_y_n_a_m_e() must
       be handed a file descriptor and return a path of the terminal
       associated with that file descriptor, while _c_t_e_r_m_i_d() returns a string
       (such as ""//ddeevv//ttttyy"") that refers to the current controlling terminal if
       used as a pathname.

RRAATTIIOONNAALLEE
       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.

       Conforming applications that use multiple threads cannot call _c_t_e_r_m_i_d()
       with NULL as the parameter. If _s is not NULL, the _c_t_e_r_m_i_d() function
       generates a string that, when used as a pathname, refers to the current
       controlling terminal for the current process. If _s is NULL, the return
       value of _c_t_e_r_m_i_d() is undefined.

       There is no additional burden on the programmer--changing to use a
       hypothetical thread-safe version of _c_t_e_r_m_i_d() 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.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _t_t_y_n_a_m_e()

       The Base Definitions volume of POSIX.1-2017, <<ssttddiioo..hh>>

CCOOPPYYRRIIGGHHTT
       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 .

       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 .



IEEE/The Open Group                  2017                           CTERMID(3)
