Fix error message when creating a file
Make the file's parents when creating it

This is only done if the 'mkpath' option is set.
Create the file when opening it if needed

That is, if the flags include O_CREAT.
Return the bytes written when writing a file