Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!usc!csun!csusac!unify!rk From: rk@unify.UUCP (Ron Kuris) Newsgroups: comp.unix.wizards Subject: unlink safe before close? Keywords: unlink before close Message-ID: <755@unify.UUCP> Date: 6 May 89 18:13:35 GMT Reply-To: rk@unify.UUCP (Ron Kuris) Distribution: na Organization: Unify Corporation, Sacramento, CA, USA Lines: 34 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@unify.UUCP {{ucdavis,csun,lll-crg}!csusac,pyramid,sequent}!unify!rk