Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    int access( const char *path, int mode );
    int _access( const char *path, int mode );
    int _waccess( const wchar_t *path, int mode );

Description:
    The access function determines if the file or directory specified by
    path exists and if it can be accessed with the file permission given by
    mode.

    The _access function is identical to access.  Use _access for ANSI
    naming conventions.

    When the value of mode is zero, only the existence of the file is
    verified.  The read and/or write permission for the file can be
    determined when mode is a combination of the bits:

    Bit     Meaning

R_OK
    test for read permission

W_OK
    test for write permission

X_OK
    test for execute permission

F_OK
    test for existence of file

    With DOS, all files have read permission; it is a good idea to test for
    read permission anyway, since a later version of DOS may support
    write-only files.

    The _waccess function is identical to access except that it accepts a
    wide-character string argument for path.

Returns:
    The access function returns zero if the file or directory exists and can
    be accessed with the specified mode.  Otherwise, -1 is returned and
     errno is set to indicate the error.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    Constant     Meaning

EACCES
    Access denied because the file's permission does not allow the specified
    access.

ENOENT
    Path or file not found.


Example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <io.h>

    void main( int argc, char *argv[] )
      {
        if( argc != 2 ) {
          fprintf( stderr, "Use: check <filename>\n" );
          exit( 1 );
        }

        if( access( argv[1], F_OK ) == 0 ) {
          printf( "%s exists\n", argv[1] );
        } else {
          printf( "%s does not exist\n", argv[1] );
          exit( EXIT_FAILURE );
        }
        if( access( argv[1], R_OK ) == 0 ) {
          printf( "%s is readable\n", argv[1] );
        }
        if( access( argv[1], W_OK ) == 0 ) {
          printf( "%s is writeable\n", argv[1] );
        }
        if( access( argv[1], X_OK ) == 0 ) {
          printf( "%s is executable\n", argv[1] );
        }
        exit( EXIT_SUCCESS );
      }

Classification:
    access is POSIX 1003.1, _access is not POSIX, _waccess is not POSIX

Systems:
     access - All, Netware

    _access - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32
    _waccess - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    chmod, fstat, open, sopen, stat

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson