I would like to go further and really extend POSIX to get the atomic operations everybody really wants. I would actually redefine the flags sent by creat() (O_CREAT|O_WRONLY|O_TRUNC) to be this "ponies" flag with the following rules:
1. If the file already exists, then other programs either see the old file or the contents of the new file when close() was called on it.
2. If the file does not already exist then other programs either see no such file or they see the file with the contents when close() was called on it.
3. If the program crashes or exits without calling close() then it is exactly like nothing ever happended.
3a. It may be useful to add some new call that "forgets" the file, ie it is "closed" in the same way as when the program exits.
This will avoid the need to use a temporary file and then rename it to get real atomic writes. And it would not use a new flag, because all programs using the creat() flags are already acting exactly like it works this way.
Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds