To be clear, running out of disk part way through writing the file is a hardware problem. Your hardware doesn't have a big enough disk :)
I don't agree with you...
I did some tests in a VM with geany and some other editors and the same situation. Here are the results: - geany => nulls out the original file - xfw (from xfe file manager) => nulls out the original file - mousepad => truncates the original file - kate => truncates the original file - gedit => preserves the original file
So, as you see there are differences between the editor implementations. Among the five tested editors, gedit does the best job. It warns that the partition is full and it doesn't change the original file.
Why not doing the same as gedit? I think gedit relies on gio operations...
Another point: you could check the available space using statvfs() before attempting to save the file. I think you said this way is not accurate, why?