Access()System call

Hi,

Is it possible to check the Existence/read/write of stdin,stdout,stderr using access() call like for the files we do.

Ex: fd=access("./hi.txt",F_OK)

Similarly I wanna check stdin/tdout/stderr using access() call

I tried using fd=access(stdout,F_OK);

But the result is -1.

I believe I did some error in writing it. Will you please suggest the correct way?

Also one more doubt with access() call. Is it True that the standard file desc of STDIN,STDOUT and STDERR are 0,1,2 respectively?
Thanks,
Ramkrix

First off, how did that ever compile, should be:

fd=access(fileno(stdout),F_OK);

access() requires a path, not an fd, for the first argument. The closest equivalent for an fd that I can think of is an fcntl with a command of F_GETFD or maybe F_GETFL. I would try those. Remember that a valid fd may not refer to a disk file at all. It could be a socket or something like that.

Hi Perdebo,

then how can we make access() sys call work with stdin, stdout, stderr.

Jim,
I tried your way, but it did not worked out. please help me.

Thanks,
Ramkrix