File:  [MW Coherent from dump] / coherent / a / usr / man / MULTI / access
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



access()               COHERENT System Call              access()




Check if a file can be accessed in a given mode

#iinncclluuddee <aacccceessss.hh>
iinntt aacccceessss(_f_i_l_e_n_a_m_e, _m_o_d_e) cchhaarr *_f_i_l_e_n_a_m_e; iinntt _m_o_d_e;

access checks whether a file  or directory can be accessed in the
mode you  wish.  filename is  the full path  name of the  file or
directory you wish to check.  mode  is the mode in which you wish
to access filename, as follows:


         AARREEAADD     Read a file
         AALLIISSTT     List the contents of a directory

         AAWWRRIITTEE    Write into a file
         AADDEELL      Delete files from a directory

         AAEEXXEECC     Execute a file
         AASSRRCCHH     Search a directory

         AAAAPPPPNNDD    Append to a file
         AACCRREEAATT    Create a file in a directory


The header file access.h defines these values, which may be logi-
cally combined to produce the mode argument.

If mode  is set to  zero, access tests only  whether filename ex-
ists, and  whether you have permission  to search all directories
that lead to it.

access returns zero if  filename can be accessed in the requested
mode, and a number greater than zero if it cannot.

access uses the  real user id and real group  id (rather than the
effective  user  id  and effective  group  id),  so  set user  id
programs can use it.

***** Example *****

The following example checks if a  file can be accessed in a par-
ticular manner.


#include <access.h>
#include <stdio.h>



main(argc, argv)
int argc; char *argv[];
{
    int mode;
    extern int access();


COHERENT Lexicon                                           Page 1




access()               COHERENT System Call              access()






    if (argc != 3) {
              fprintf(stderr, "Usage: access filename mode\n");
              exit(1);
    }



    switch (*argv[2]) {
    case 'x':
              mode = AEXEC;
              break;



    case 'w':
              mode = AWRITE;
              break;



    case 'r':
              mode = AREAD;
              break;



    default:
              fprintf(stderr,
              "modes: x = execute, w = write, r = read\n");
              exit(1);
              break;
    }



    if (access(argv[1], mode)) {
              printf("file %s not found in mode %d\n", argv[1], mode);
              exit(0);
    } else
              printf("file %s accessible in mode %d\n",
               argv[1], mode);
    exit(0);
}


***** See Also *****

access.h, COHERENT system calls, path()






COHERENT Lexicon                                           Page 2



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.