Name

waccess - checks user's permissions for a file

Library

libc.lib

Synopsis

  #include <unistd.h>
  #include <wchar.h>
  int waccess (const wchar_t *path, int mode);

Return values

Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Detailed description

The waccess system call checks the accessibility of the file named by the path argument for the access permissions indicated by the mode argument. The value of mode is either the bitwise-inclusive OR of the access permissions to be checked (R_OK for read permission, W_OK for write permission, and X_OK for execute/search permission), or the existence test (F_OK.)

For additional information, see the File access Permission section of intro . X_OK, the file may not actually have execute permission bits set. Likewise for R_OK and W_OK.

Note that as execute-bit for file is not supported .Hence waccess system call for X_OK is undefined.


Examples

/**
 * Detailed description: This sample code checks read-ok accessibility of file Example.c
 *
 * Precondtions: Example.txt file should be present in working directory.
**/
#include <unistd.h>
#include <wchar.h>
int main()
{
  if(waccess("Example.c" ,R_OK)  < 0)  
  {
    printf("Read operation on the file is not permitted \n") ;
    return -1 ;
  }
  printf("Read operation permitted on Example.c file \n") ;
  return 0 ;
}

         

Output

Read operation permitted on Example.c file

         


Errors

Access to the file is denied if:
[ENOTDIR]
  A component of the path prefix is not a directory.
[ENAMETOOLONG]
  A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters .
[ENOENT]
  The named file does not exist.
[EACCES]
  Permission bits of the file mode do not permit the requested access, or search permission is denied on a component of the path prefix.

See also

wchmod, wstat

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top