On 2002-06-11, Muli Ben-Yehuda wrote: > Is there a way to open a file (get an fd) and then delete it, in one > atomic operation? > > I need to open a temporary file (but with a fixed name, so mkstemp() > and friends are not an option) and then make sure it doesn't remain > behind if the program should die unexpectedly. Doing > > open("foo", ...); > unlink("foo", ...); > > is obviously unsafe, since foo might be pointing to something else by > the time I unlink it. Suggestions?
You know that you can do the unlink *immediately* after the open, right? you can still use the fd after that, but your "foo" link will live only for a couple of microseconds (or whatever). If I understand you correctly, you want to avoid even those microseconds? you want to make sure that the "foo" link *never* exists in any directory? (then why do you care for a fixed name, if the name never exists?) ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]