Chapter Contents |
Previous |
Next |
access |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTION | |
IMPLEMENTATION | |
EXAMPLES | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <sys/types.h> #include <unistd.h> int access(const char *path, int amode);
SAS/C enables the header file
<fcntl.h>
to be included in place of
<unistd.h>
.
DESCRIPTION |
The
access
function determines if a file exists and if that file can be read
or written.
path
points to a filename
of any style. The type of access tested for is given by
amode
, which can be the sum of one or more of the following symbols:
F_OK
|
indicates that the file exists. |
R_OK
|
indicates read access. |
W_OK
|
indicates write access. |
X_OK
|
indicates execute access. |
Use the bitwise inclusive OR to test several access
modes simultaneously. You cannot use OR to specify
F_OK
with another symbol.
X_OK
is
ignored, except for USS hierarchical file system (HFS) files.
RETURN VALUE |
The
access
function returns 0 if the file exists and if the type (or types) of
access specified by
amode
is allowed.
If the file does not exist or the specified type of access is not allowed, -1
is returned.
CAUTION |
A sequential file exists if it contains any data (as recorded in the VTOC). For more information on OS/390 file existence, see I/O Functions.
A 0 return value from
access
does not
necessarily mean that the file can be opened, even if the
type of access is allowed. For example, a file may fail to open because incorrect
DCB information is specified. A -1 return value always indicates that
the file cannot be opened with the specified type of access.
If the filemode is not specified,
*
is used, unless
amode
indicates
that write access is to be tested. In this case,
A1
is used as the filemode.
If the filename is in
xed
style and XEDIT is not active or the file is not found in XEDIT, the
file is searched for on disk. Write access (
W_OK
) is not allowed for
xed
or
sfd
style files.
Under CMS, the
access
function cannot be used with VSAM files.
IMPLEMENTATION |
Any
amode
value can be tested for any device type. If the mode is not valid
for a device, -1 is returned.
EXAMPLES |
#include <fcntl.h> #include <stdio.h> main() { int rc; /* Does the program have read and write access to the */ /* TSO ISPF profile dataset? */ rc = access("tso:ispf.profile", R_OK + W_OK); if (rc == 0) puts("Read and write access exists."); else puts("Read and write access does not exist."); /* Does the member DATA1 exist in the partitioned */ /* dataset referred to by the ddname MYPROG? */ rc = access("tso:myprog(data1)", 0); if (rc == 0) puts("File exists."); else puts("File does not exist."); /* Can SYS1.PARMLIB be updated? */ rc = access("dsn:sys1.parmlib", W_OK); if (rc == 0) puts("Yes, SYS1.PARMLIB can be updated."); else puts("SYS1.PARMLIB cannot be updated."); }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.