RMDIR(3)                   POSIX Programmer's Manual                  RMDIR(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
       rmdir -- remove a directory

SSYYNNOOPPSSIISS
       #include <unistd.h>

       int rmdir(const char *_p_a_t_h);

DDEESSCCRRIIPPTTIIOONN
       The _r_m_d_i_r() function shall remove a directory whose name is given by
       _p_a_t_h.  The directory shall be removed only if it is an empty directory.

       If the directory is the root directory or the current working directory
       of any process, it is unspecified whether the function succeeds, or
       whether it shall fail and set _e_r_r_n_o to [[EEBBUUSSYY]].

       If _p_a_t_h names a symbolic link, then _r_m_d_i_r() shall fail and set _e_r_r_n_o to
       [[EENNOOTTDDIIRR]].

       If the _p_a_t_h argument refers to a path whose final component is either
       dot or dot-dot, _r_m_d_i_r() shall fail.

       If the directory's link count becomes 0 and no process has the
       directory open, the space occupied by the directory shall be freed and
       the directory shall no longer be accessible. If one or more processes
       have the directory open when the last link is removed, the dot and dot-
       dot entries, if present, shall be removed before _r_m_d_i_r() returns and no
       new entries may be created in the directory, but the directory shall
       not be removed until all references to the directory are closed.

       If the directory is not an empty directory, _r_m_d_i_r() shall fail and set
       _e_r_r_n_o to [[EEEEXXIISSTT]] or [[EENNOOTTEEMMPPTTYY]].

       Upon successful completion, _r_m_d_i_r() shall mark for update the last data
       modification and last file status change timestamps of the parent
       directory.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, the function _r_m_d_i_r() shall return 0.
       Otherwise, -1 shall be returned, and _e_r_r_n_o set to indicate the error.
       If -1 is returned, the named directory shall not be changed.

EERRRROORRSS
       The _r_m_d_i_r() 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 removed.

       EEBBUUSSYY  The directory to be removed is currently in use by the system or
              some process and the implementation considers this to be an
              error.

       [EEXIST] or [ENOTEMPTY]
                   The _p_a_t_h argument names a directory that is not an empty
                   directory, or there are hard links to the directory other
                   than dot or a single entry in dot-dot.

       EEIINNVVAALL      The _p_a_t_h argument contains a last component that is dot.

       EEIIOO         A physical I/O error has occurred.

       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 the
                   _p_a_t_h argument names a nonexistent directory or points to an
                   empty string.

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

       [EPERM] or [EACCES]
                   The S_ISVTX flag is set on the directory containing the
                   file referred to by the _p_a_t_h argument and the process does
                   not satisfy the criteria specified in the Base Definitions
                   volume of POSIX.1-2008, _S_e_c_t_i_o_n _4_._2, _D_i_r_e_c_t_o_r_y _P_r_o_t_e_c_t_i_o_n.

       EERROOFFSS       The directory entry to be removed resides on a read-only
                   file system.

       The _r_m_d_i_r() 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
   RReemmoovviinngg aa DDiirreeccttoorryy
       The following example shows how to remove a directory named
       //hhoommee//ccnndd//mmoodd11.

           ##iinncclluuddee <<uunniissttdd..hh>>

           int status;
           ...
           status = rmdir("/home/cnd/mod1");

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       The _r_m_d_i_r() and _r_e_n_a_m_e() functions originated in 4.2 BSD, and they used
       [[EENNOOTTEEMMPPTTYY]] for the condition when the directory to be removed does not
       exist or _n_e_w already exists. When the 1984 /usr/group standard was
       published, it contained [[EEEEXXIISSTT]] instead. When these functions were
       adopted into System V, the 1984 /usr/group standard was used as a
       reference. Therefore, several existing applications and implementations
       support/use both forms, and no agreement could be reached on either
       value. All implementations are required to supply both [[EEEEXXIISSTT]] and
       [[EENNOOTTEEMMPPTTYY]] in _<_e_r_r_n_o_._h_> with distinct values, so that applications can
       use both values in C-language ccaassee statements.

       The meaning of deleting _p_a_t_h_n_a_m_e//ddoott is unclear, because the name of
       the file (directory) in the parent directory to be removed is not
       clear, particularly in the presence of multiple links to a directory.

       The POSIX.1-1990 standard was silent with regard to the behavior of
       _r_m_d_i_r() when there are multiple hard links to the directory being
       removed. The requirement to set _e_r_r_n_o to [[EEEEXXIISSTT]] or [[EENNOOTTEEMMPPTTYY]]
       clarifies the behavior in this case.

       If the current working directory of the process is being removed, that
       should be an allowed error.

       Virtually all existing implementations detect [[EENNOOTTEEMMPPTTYY]] or the case
       of dot-dot. The text in _S_e_c_t_i_o_n _2_._3, _E_r_r_o_r _N_u_m_b_e_r_s about returning any
       one of the possible errors permits that behavior to continue. The
       [[EELLOOOOPP]] error may be returned if more than {SYMLOOP_MAX} symbolic links
       are encountered during resolution of the _p_a_t_h argument.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._3, _E_r_r_o_r _N_u_m_b_e_r_s, _m_k_d_i_r(), _r_e_m_o_v_e(), _r_e_n_a_m_e(), _u_n_l_i_n_k()

       The Base Definitions volume of POSIX.1-2008, _S_e_c_t_i_o_n _4_._2, _D_i_r_e_c_t_o_r_y
       _P_r_o_t_e_c_t_i_o_n, <<uunniissttdd..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                             RMDIR(3)
