This documentation is archived and is not being maintained.

_access, _waccess

Determine file-access permission.

int _access( 
   const char *path, 
   int mode 
int _waccess( 
   const wchar_t *path, 
   int mode 


File or directory path.
Permission setting.

Return Value

Each function returns 0 if the file has the given mode. The function returns –1 if the named file does not exist or is not accessible in the given mode; in this case, errno is set as follows:

Access denied: file's permission setting does not allow specified access.
Filename or path not found.

See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, return codes.


When used with files, the _access function determines whether the specified file exists and can be accessed as specified by the value of mode. When used with directories, _access determines only whether the specified directory exists; in Windows NT and Windows 2000, all directories have read and write access.

mode value Checks file for
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission

_waccess is a wide-character version of _access; the path argument to _waccess is a wide-character string. _waccess and _access behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_taccess _access _access _waccess


Routine Required header Optional headers Compatibility
_access <io.h> <errno.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_waccess <wchar.h> or <io.h> <errno.h> Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


This example uses _access to check the file named crt_ACCESS.C to see if it exists and if writing is allowed.

// crt_access.c
#include  <io.h>
#include  <stdio.h>
#include  <stdlib.h>

int main( void )
   /* Check for existence */
   if( (_access( "crt_ACCESS.C", 0 )) != -1 )
      printf( "File crt_ACCESS.C exists\n" );
      /* Check for write permission */
      /* assume file is read-only */
      if( (_access( "crt_ACCESS.C", 2 )) == -1 )
         printf( "File crt_ACCESS.C does not have write permission\n" );


File crt_ACCESS.C exists
File crt_ACCESS.C does not have write permission

See Also

File Handling Routines | _chmod | _fstat | _open | _stat | Run-Time Routines and .NET Framework Equivalents