access()

The Grey Wolf greywolf at unisoft.UUCP
Wed Feb 6 10:51:10 AEST 1991


In article <15051 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
/*
 * ... one is said to have access for execution when in fact an attempt to
 * execute cannot succeed.
 *
 * There are other problems, but that should be enough to discourage use of
 * access(). It is usually simpler and more reliable to simply attempt the
 * desired operation and see whether it succeeds.
 */

Sometimes, we only want to verify that a file exists, in which case it
is more tended to use access() for this.  We may not do anything with it
-- it may be a lock file.  creat() doesn't work for this; open with
O_CREAT|O_EXCL set is a more expensive call, after which we might not
want to do anything with the file descriptor we get back.

[ I was going to argue that an access(dirpath, X_OK) is faster than
chdir(dirpath);, but my argument is kind of null since, generally, if
one wishes to verify that a directory is executable (searchable/
residable), one will probably be performing a chdir() to it rather
soon afterwards. ]

-- 
thought:  I ain't so damb dumn!	| Your brand new kernel just dump core on you
war: Invalid argument		| And fsck can't find root inode 2
				| Don't worry -- be happy...
...!{ucbvax,acad,uunet,amdahl,pyramid}!unisoft!greywolf



More information about the Comp.lang.c mailing list