On Thu, Oct 14, 2010 at 1:20 PM, Cristian Rodríguez <crrodriguez@opensuse.org> wrote:
El 14/10/10 13:38, Bogdan Cristea escribió:
tmpfile() creates a temporary file which is automatically delete when the file descriptor is closed or the program ends. Just wondering, how this behavior is achieved ?
file is "created" internally with mkstemp(3) and inmediately unlink(2)'ed from the filesystem (the _name_ is gone but the open file descriptor remains available until closing-....)
Are there some options passed when the file is created ?
the file is opened with O_RDWR|O_CREAT|O_EXCL.
For further clarification, The unlink (delete) code in the kernel does 2 things of interest for this: - decrement link count - if file is not open by any userspace app and link count == 0, then delete file In this case the if fails because the app itself has the file open, so the file is left in place with a link count of 0. Then every time any file is closed the kernel re-performs the last check above. In this case it will be zero and it is deleted. Greg -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org