ACCESS(3)                  POSIX Programmer's Manual                 ACCESS(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
       access, faccessat -- determine accessibility of a file relative to
       directory file descriptor

SSYYNNOOPPSSIISS
       #include <unistd.h>

       int access(const char *_p_a_t_h, int _a_m_o_d_e);
       int faccessat(int _f_d, const char *_p_a_t_h, int _a_m_o_d_e, int _f_l_a_g);

DDEESSCCRRIIPPTTIIOONN
       The _a_c_c_e_s_s() function shall check the file named by the pathname
       pointed to by the _p_a_t_h argument for accessibility according to the bit
       pattern contained in _a_m_o_d_e, using the real user ID in place of the
       effective user ID and the real group ID in place of the effective group
       ID.

       The value of _a_m_o_d_e is either the bitwise-inclusive OR of the access
       permissions to be checked (R_OK, W_OK, X_OK) or the existence test
       (F_OK).

       If any access permissions are checked, each shall be checked
       individually, as described in the Base Definitions volume of
       POSIX.1-2008, _S_e_c_t_i_o_n _4_._4, _F_i_l_e _A_c_c_e_s_s _P_e_r_m_i_s_s_i_o_n_s, except that where
       that description refers to execute permission for a process with
       appropriate privileges, an implementation may indicate success for X_OK
       even if execute permission is not granted to any user.

       The _f_a_c_c_e_s_s_a_t() function shall be equivalent to the _a_c_c_e_s_s() function,
       except in the case where _p_a_t_h specifies a relative path. In this case
       the file whose accessibility is to be determined shall be located
       relative to the directory associated with the file descriptor _f_d
       instead of the current working directory. If the file descriptor was
       opened without O_SEARCH, the function shall check whether directory
       searches are permitted using the current permissions of the directory
       underlying the file descriptor. If the file descriptor was opened with
       O_SEARCH, the function shall not perform the check.

       If _f_a_c_c_e_s_s_a_t() is passed the special value AT_FDCWD in the _f_d
       parameter, the current working directory shall be used and the behavior
       shall be identical to a call to _a_c_c_e_s_s().

       Values for _f_l_a_g are constructed by a bitwise-inclusive OR of flags from
       the following list, defined in _<_f_c_n_t_l_._h_>:

       AT_EACCESS  The checks for accessibility are performed using the
                   effective user and group IDs instead of the real user and
                   group ID as required in a call to _a_c_c_e_s_s().

RREETTUURRNN VVAALLUUEE
       Upon successful completion, these functions shall return 0. Otherwise,
       these functions shall return -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       These functions shall fail if:

       EEAACCCCEESS Permission bits of the file mode do not permit the requested
              access, or search permission is denied on a component of the
              path prefix.

       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.

       EERROOFFSS  Write access is requested for a file on a read-only file system.

       The _f_a_c_c_e_s_s_a_t() function shall fail if:

       EEAACCCCEESS _f_d was not opened with O_SEARCH and the permissions of the
              directory underlying _f_d do not permit directory searches.

       EEBBAADDFF  The _p_a_t_h argument does not specify an absolute path and the _f_d
              argument is neither AT_FDCWD nor a valid file descriptor open
              for reading or searching.

       EENNOOTTDDIIRR
              The _p_a_t_h argument is not an absolute path and _f_d is a file
              descriptor associated with a non-directory file.

       These functions may fail if:

       EEIINNVVAALL The value of the _a_m_o_d_e argument is invalid.

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

       EETTXXTTBBSSYY
              Write access is requested for a pure procedure (shared text)
              file that is being executed.

       The _f_a_c_c_e_s_s_a_t() function may fail if:

       EEIINNVVAALL The value of the _f_l_a_g argument is not valid.

       _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
   TTeessttiinngg ffoorr tthhee EExxiisstteennccee ooff aa FFiillee
       The following example tests whether a file named mmyyffiillee exists in the
       //ttmmpp directory.

           ##iinncclluuddee <<uunniissttdd..hh>>
           ......
           iinntt rreessuulltt;;
           ccoonnsstt cchhaarr **ppaatthhnnaammee == ""//ttmmpp//mmyyffiillee"";;

           result = access (pathname, F_OK);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Additional values of _a_m_o_d_e other than the set defined in the
       description may be valid; for example, if a system has extended access
       controls.

       The use of the AT_EACCESS value for _f_l_a_g enables functionality not
       available in _a_c_c_e_s_s().

RRAATTIIOONNAALLEE
       In early proposals, some inadequacies in the _a_c_c_e_s_s() function led to
       the creation of an _e_a_c_c_e_s_s() function because:

        1. Historical implementations of _a_c_c_e_s_s() do not test file access
           correctly when the process' real user ID is superuser. In
           particular, they always return zero when testing execute
           permissions without regard to whether the file is executable.

        2. The superuser has complete access to all files on a system. As a
           consequence, programs started by the superuser and switched to the
           effective user ID with lesser privileges cannot use _a_c_c_e_s_s() to
           test their file access permissions.

       However, the historical model of _e_a_c_c_e_s_s() does not resolve problem
       (1), so this volume of POSIX.1-2008 now allows _a_c_c_e_s_s() to behave in
       the desired way because several implementations have corrected the
       problem. It was also argued that problem (2) is more easily solved by
       using _o_p_e_n(), _c_h_d_i_r(), or one of the _e_x_e_c functions as appropriate and
       responding to the error, rather than creating a new function that would
       not be as reliable. Therefore, _e_a_c_c_e_s_s() is not included in this volume
       of POSIX.1-2008.

       The sentence concerning appropriate privileges and execute permission
       bits reflects the two possibilities implemented by historical
       implementations when checking superuser access for X_OK.

       New implementations are discouraged from returning X_OK unless at least
       one execution permission bit is set.

       The purpose of the _f_a_c_c_e_s_s_a_t() function is to enable the checking of
       the accessibility of files in directories other than the current
       working directory without exposure to race conditions. Any part of the
       path of a file could be changed in parallel to a call to _a_c_c_e_s_s(),
       resulting in unspecified behavior. By opening a file descriptor for the
       target directory and using the _f_a_c_c_e_s_s_a_t() function it can be
       guaranteed that the file tested for accessibility is located relative
       to the desired directory.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_h_m_o_d(), _f_s_t_a_t_a_t()

       The Base Definitions volume of POSIX.1-2008, _S_e_c_t_i_o_n _4_._4, _F_i_l_e _A_c_c_e_s_s
       _P_e_r_m_i_s_s_i_o_n_s, <<ffccnnttll..hh>>, <<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                            ACCESS(3)
