Writing to A NON-Existing File in "C"

der Mouse mouse at mcgill-vision.UUCP
Sat Apr 23 18:08:34 AEST 1988


In article <147 at obie.UUCP>, wes at obie.UUCP (Barnacle Wes) writes:
> 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:
[code which is supposed to do that - I didn't check it]

This is wrong if the program might ever run setuid.  access() does not
exist to allow vanilla users to find out whether files are accessible;
it's for setuid programs to determine whether the real user can access
a file.  (It's the wrong way to do even that, because of the resulting
window, but that's another can of worms.)  The right way to find out
whether you can open a file for write is...try it!

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.unix.questions mailing list