FTOK(3)                    POSIX Programmer's Manual                   FTOK(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
       ftok -- generate an IPC key

SSYYNNOOPPSSIISS
       #include <sys/ipc.h>

       key_t ftok(const char *_p_a_t_h, int _i_d);

DDEESSCCRRIIPPTTIIOONN
       The _f_t_o_k() function shall return a key based on _p_a_t_h and _i_d that is
       usable in subsequent calls to _m_s_g_g_e_t(), _s_e_m_g_e_t(), and _s_h_m_g_e_t().  The
       application shall ensure that the _p_a_t_h argument is the pathname of an
       existing file that the process is able to _s_t_a_t(), with the exception
       that if _s_t_a_t() would fail with [[EEOOVVEERRFFLLOOWW]] due to file size, _f_t_o_k()
       shall still succeed.

       The _f_t_o_k() function shall return the same key value for all paths that
       name the same file, when called with the same _i_d value, and should
       return different key values when called with different _i_d values or
       with paths that name different files existing on the same file system
       at the same time. It is unspecified whether _f_t_o_k() shall return the
       same key value when called again after the file named by _p_a_t_h is
       removed and recreated with the same name.

       Only the low-order 8-bits of _i_d are significant. The behavior of _f_t_o_k()
       is unspecified if these bits are 0.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _f_t_o_k() shall return a key. Otherwise,
       _f_t_o_k() shall return (kkeeyy__tt)-1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _f_t_o_k() function shall fail if:

       EEAACCCCEESS Search permission is denied for a component of the path prefix.

       EEIIOO    An error occurred while reading from the file system.

       EELLOOOOPP  A loop exists in symbolic links encountered during resolution of
              the _p_a_t_h argument.

       EENNAAMMEETTOOOOLLOONNGG
              The length of a component of a pathname is longer than
              {NAME_MAX}.

       EENNOOEENNTT A component of _p_a_t_h does not name an existing file or _p_a_t_h is an
              empty string.

       EENNOOTTDDIIRR
              A component of the path prefix names an existing file that is
              neither a directory nor a symbolic link to a directory, or the
              _p_a_t_h argument contains at least one non-<slash> character and
              ends with one or more trailing <slash> characters and the last
              pathname component names an existing file that is neither a
              directory nor a symbolic link to a directory.

       The _f_t_o_k() function may fail if:

       EELLOOOOPP  More than {SYMLOOP_MAX} symbolic links were encountered during
              resolution of the _p_a_t_h argument.

       EENNAAMMEETTOOOOLLOONNGG
              The length of a pathname exceeds {PATH_MAX}, or pathname
              resolution of a symbolic link produced an intermediate result
              with a length that exceeds {PATH_MAX}.

       _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
   GGeettttiinngg aann IIPPCC KKeeyy
       The following example gets a key based on the pathname //ttmmpp and the ID
       value _a.  It also assigns the value of the resulting key to the _s_e_m_k_e_y
       variable so that it will be available to a later call to _s_e_m_g_e_t(),
       _m_s_g_g_e_t(), or _s_h_m_g_e_t().

           ##iinncclluuddee <<ssyyss//iippcc..hh>>
           ......
           kkeeyy__tt sseemmkkeeyy;;

           if ((semkey = ftok("/tmp", 'a')) == (key_t) -1) {
               perror("IPC error: ftok"); exit(1);
           }

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       For maximum portability, _i_d should be a single-byte character.

       Applications should not assume that the resulting key value is unique.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       Future versions of this standard may add new interfaces to provide
       unique keys.

SSEEEE AALLSSOO
       _m_s_g_g_e_t(), _s_e_m_g_e_t(), _s_h_m_g_e_t()

       The Base Definitions volume of POSIX.1-2008, <<ssyyss__iippcc..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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.unix.org/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                  2013                              FTOK(3)
