Fix the file position handling of the read and write calls