Definition read_file (nbytes: nat): list memval := read_file_aux nbytes (get_size f) fptr.
Fixpoint write_file_aux (bytes: list memval) (sz cur: nat): (nat -> memval)*nat :=
match bytes with
| nil => (contents, O)
| byte::bytes' =>
match write_file_aux bytes' sz (S cur) with (contents', nbytes) =>
(fun ofs => if eq_nat_dec ofs cur then byte else contents' ofs, S nbytes)
end
end.

(* Specifications: *)
Lemma write_file_aux_length (bytes: list memval) (sz cur: nat):
snd (write_file_aux bytes sz cur)=length bytes.