Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>access() check file permission setting</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
access()                 Check File Permission Setting

 #include   <io.h>

 int        access(pathname,mode);
 char       *pathname;                   Name of file or directory
 int        mode;                        Permission setting

    access() checks whether the file or directory specified as `pathname'
    exists, and whether its read/write mode matches that that of the
    argument `mode'.  'mode' can have any of the following values:

                Value       Checks For
                 00      Existence only
                 02      Write permission
                 04      Read permission
                 06      Read and write permission

    Returns:    Zero if the file has the given mode, or -1 if the file
                does not exist or does not have the given mode.  If an
                error occurs, 'errno' is set to one of the following:

                    EACCES    Access denied; file's permission does
                              not allow the specified access
                    ENOENT    File or pathname not found.

      Notes:    In MS-DOS all existing files have read access, so this
                function determines whether or not a file can be written
                to. In MS-DOS all directories have read and write access,
                so this function determines whether or not a directory
                exists.

  -------------------------------- Example ---------------------------------

    The following statements check for write permission and print an
    error message.

           #include <io.h>
           #include <stdlib.h>                /* For perror */

           main()
           {
               if ((access("inventory.dta",2)) == -1)
                   perror("cannot write to inventory file");
           }

See Also: chmod() fstat() open() stat()

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