Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AIX and C: How do I use the 'access' function

Status
Not open for further replies.

akn846

Technical User
Oct 16, 2001
51
GB
I have a program which I developed using the GNU compilers on a Linux system at home - which I expected I would be able to get to run quite readily on the AIX server at work.

But not to be.

Basically the program takes two parameters, one of which is a filename that is to be renamed and moved into a directory which is passed as the second parameter.

I am trying to use the 'access' function within unistd.h file to check that the file exists - and that the user has the correct permission to write/execute the parent directory in order for it to rename.

Works fine on Linux - but fails miserably on AIX!!

The line of code I'm using to check that the file exists is:

if (access (argv[1], F_OK) < 0)

and the code I'm using to check the permissions on the parent directory is:

if (access(argv[2], W_OK) < 0 ) || (access(argv[2], X_OK) < 0)...

Can anyone suggest why when I call 'access' I always get a -1 result - I even attempted to include the 'access.h' file but this hasn't worked either.

Any help would be much appreciated.

Regards
 
Well, the man page states...

#include <unistd.h>

int access (PathName, Mode)
char *PathName;
int Mode;

It &quot;seems&quot; like you are calling it correctly assuming you are
including the &quot;unistd.h&quot; header file.
Try using &quot;perror()&quot; and see what the system &quot;tells&quot; you the
problem is. Also, you should just be able to do...

if( access(argv[2], W-OK | X_OK) < 0)
{
perror(argv[0]);
exit(1);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top