let file_copy ?(perm=0o666) ?(flag=O_TRUNC) input_name output_name =
let fd_in = openfile input_name [O_RDONLY] 0 in
let fd_out = openfile output_name [O_WRONLY; O_CREAT; flag] perm in
let rec copy_loop () =
match read fd_in buffer 0 buffer_size with
0 -> ()
| r -> ignore (write fd_out buffer 0 r); copy_loop () in
copy_loop ();
close fd_in;
close fd_out