unlink safe before close?
Ron Kuris
rk at unify.UUCP
Sun May 7 04:13:35 AEST 1989
I heard from someone in our organization that the following code
was non-portable. Does anyone know of some machines were it does
not work? Obviously MS/DOS will fail (but who cares?).
The intent is to create a temporary file that noone else
can conflict with, and is automatically removed when the program
terminates (either normally or abnormally):
main()
{
int fd;
if ((fd = creat("/tmp/who-cares", 0600)) < 0)
{
/* failure code... */
}
unlink("/tmp/who-cares");
/* initialize some-stuff and some-size here with whatever */
write(fd, some-stuff, some-size);
/* do whatever else you want with the fd: reads, writes, etc */
.
.
.
/* finally just exit which closes and cleans up everything */
exit(0);
}
Note that if a core occurs somewhere in the . . . area, the file will
automatically be erased. I think this is pretty peachy :-).
Comments?
--
Ron Kuris (916) 920-9092
rk at unify.UUCP
{{ucdavis,csun,lll-crg}!csusac,pyramid,sequent}!unify!rk
More information about the Comp.unix.wizards
mailing list