Eventhough there are similar questions like here or here, I have a question about a different case.
By using C/C++, I want to write some bytes to a file. Initially file has data. Simply, I update the content of file : I open, write and close. However, if it fails during write and if we are unable to handle the failure (for example, application crash, interrupt, electricity shutdown etc.), what is guaranteed in output file between the list below? Which situation can happen, which cannot?
- File may be empty (Deleted existing values and couldn't write new ones)
- File stays locked
- File may contain both old values and new values (i.e. first 5 lines are new values, last 5 lines are old values)
- File may contain old value.
- Anything other that I don't expect?
If you can give me OS independent approaches, I would be glad
Thanks