Writing to A NON-Existing File in "C"

Dave Decot decot at hpisod2.HP.COM
Tue Apr 19 13:27:24 AEST 1988


> > I'd do it slightly different.  Unless you need speed, try using
> > access(2) to determine if the file is available to you, and if not
> > open /dev/null for writing:
> >
> > [little C fragment to do the above]
> 
> AAAAAAAAAARGH!  Please do not use access(2) as a handy-dandy
> "does the file exist?" function.  It is designed to be used
> by set-{user,group}-id programs to see if the underlying user
> has permission to access the file in the requested manner.

Uh...I think a file's existence is independent of your user-id.

It's perfectly acceptable to use access(2) the F_OK (0) value of amode
it to determine whether files exist.  Such calls succeed exactly when
calls to stat(2) succeed.

access(2) should not be used to determine the other access permissions
except in setuid programs, and even then, not for testing execute
access by setuid-root programs.

Dave Decot
hpda!decot



More information about the Comp.unix.wizards mailing list