Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/a/access.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/a/access.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/a/access.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/a/access.html on line 8
Check to see if a file or directory can be accessed
#include <unistd.h>
int access( const char * path,
int amode );
- path
- The path to the file or directory that you want to access.
- amode
- The access mode you want to check.
This must be either:
- F_OK — test for file existence.
or a bitwise ORing of the following access permissions
to be checked, as defined in the header <unistd.h>:
- R_OK — test for read permission.
- W_OK — test for write permission.
- X_OK — for a directory, test for search permission.
Otherwise, test for execute permission.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The access() function checks to see if the file or directory
specified by path exists and if it can be accessed with the file
access permissions given by amode.
However, unlike other functions
(open() for example),
it uses the real user ID and real group ID in place of the effective user and group IDs.
- 0
- The file or directory exists and can be accessed with the specified mode.
- -1
- An error occurred (errno is set).
- EACCES
- The permissions specified by amode are denied, or search
permission is denied on a component of the path prefix.
- EINVAL
- An invalid value was specified for amode.
- ELOOP
- Too many levels of symbolic links or prefixes.
- ENAMETOOLONG
- The length of the path string exceeds
PATH_MAX, or a pathname component is longer than NAME_MAX.
- ENOENT
- A component of the path isn't valid.
- ENOSYS
- The access() function isn't implemented for the filesystem specified
in path.
- ENOTDIR
- A component of the path prefix isn't a directory.
- EROFS
- Write access was requested for a file residing on a read-only file system.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv )
{
if( argc!= 2 ) {
fprintf( stderr,
"use: readable <filename>\n" );
return EXIT_FAILURE;
}
if( !access( argv[1], R_OK ) ) {
printf( "ok to read %s\n", argv[1] );
return EXIT_SUCCESS;
} else {
perror( argv[1] );
return EXIT_FAILURE;
}
}
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
chmod(),
eaccess,
errno,
fstat(),
open(),
stat()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/a/access.html on line 233
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/a/access.html on line 233