MKDTEMP(3)                 POSIX Programmer's Manual                MKDTEMP(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
       mkdtemp, mkstemp -- create a unique directory or file

SSYYNNOOPPSSIISS
       #include <stdlib.h>

       char *mkdtemp(char *_t_e_m_p_l_a_t_e);
       int mkstemp(char *_t_e_m_p_l_a_t_e);

DDEESSCCRRIIPPTTIIOONN
       The _m_k_d_t_e_m_p() function uses the contents of _t_e_m_p_l_a_t_e to construct a
       unique directory name. The string provided in _t_e_m_p_l_a_t_e shall be a
       pathname ending with six trailing ''XX''s.  The _m_k_d_t_e_m_p() function shall
       replace each ''XX'' with a character from the portable filename character
       set. The characters are chosen such that the resulting name does not
       duplicate the name of an existing file at the time of a call to
       _m_k_d_t_e_m_p().  The unique directory name is used to attempt to create the
       directory using mode 0700 as modified by the file creation mask.

       The _m_k_s_t_e_m_p() function shall replace the contents of the string pointed
       to by _t_e_m_p_l_a_t_e by a unique pathname, and return a file descriptor for
       the file open for reading and writing. The _m_k_s_t_e_m_p() function shall
       create the file, and obtain a file descriptor for it, as if by a call
       to:

           ooppeenn((ppaatthhnnaammee,, OO__RRDDWWRR||OO__CCRREEAATT||OO__EEXXCCLL,, SS__IIRRUUSSRR||SS__IIWWUUSSRR))

       The function thus prevents any possible race condition between testing
       whether the file exists and opening it for use. The string in _t_e_m_p_l_a_t_e
       should look like a pathname with six trailing ''XX''s; _m_k_s_t_e_m_p() replaces
       each ''XX'' with a character from the portable filename character set. The
       characters are chosen such that the resulting name does not duplicate
       the name of an existing file at the time of a call to _m_k_s_t_e_m_p().

RREETTUURRNN VVAALLUUEE
       Upon successful completion, the _m_k_d_t_e_m_p() function shall return a
       pointer to the string containing the directory name if it was created.
       Otherwise, it shall return a null pointer and shall set _e_r_r_n_o to
       indicate the error.

       Upon successful completion, the _m_k_s_t_e_m_p() function shall return an open
       file descriptor. Otherwise, it shall return -1 if no suitable file
       could be created.

EERRRROORRSS
       The _m_k_d_t_e_m_p() function shall fail if:

       EEAACCCCEESS Search permission is denied on a component of the path prefix,
              or write permission is denied on the parent directory of the
              directory to be created.

       EEIINNVVAALL The string pointed to by _t_e_m_p_l_a_t_e does not end in ""XXXXXXXXXXXX"".

       EELLOOOOPP  A loop exists in symbolic links encountered during resolution of
              the path of the directory to be created.

       EEMMLLIINNKK The link count of the parent directory would exceed {LINK_MAX}.

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

       EENNOOEENNTT A component of the path prefix specified by the _t_e_m_p_l_a_t_e
              argument does not name an existing directory.

       EENNOOSSPPCC The file system does not contain enough space to hold the
              contents of the new directory or to extend the parent directory
              of the new directory.

       EENNOOTTDDIIRR
              A component of the path prefix names an existing file that is
              neither a directory nor a symbolic link to a directory.

       EERROOFFSS  The parent directory resides on a read-only file system.

       The _m_k_d_t_e_m_p() function may fail if:

       EELLOOOOPP  More than {SYMLOOP_MAX} symbolic links were encountered during
              resolution of the path of the directory to be created.

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

       The error conditions for the _m_k_s_t_e_m_p() function are defined in _o_p_e_n().

       _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
   GGeenneerraattiinngg aa PPaatthhnnaammee
       The following example creates a file with a 10-character name beginning
       with the characters ""ffiillee"" and opens the file for reading and writing.
       The value returned as the value of _f_d is a file descriptor that
       identifies the file.

           ##iinncclluuddee <<ssttddlliibb..hh>>
           ......
           cchhaarr tteemmppllaattee[[]] == ""//ttmmpp//ffiilleeXXXXXXXXXXXX"";;
           iinntt ffdd;;

           fd = mkstemp(template);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       It is possible to run out of letters.

       The _m_k_d_t_e_m_p() and _m_k_s_t_e_m_p() functions need not check to determine
       whether the filename part of _t_e_m_p_l_a_t_e exceeds the maximum allowable
       filename length.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _g_e_t_p_i_d(), _m_k_d_i_r(), _o_p_e_n(), _t_m_p_f_i_l_e(), _t_m_p_n_a_m()

       The Base Definitions volume of POSIX.1-2008, <<ssttddlliibb..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                           MKDTEMP(3)
