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/C++ v10.0 : C library - <b>synopsis:</b> 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 );

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.

    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:

    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.

Returns:
    The access 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.

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

    ENOENT
        Path or file not found.


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

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:
    POSIX 1003.1

Systems:
    All

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