From 669781b86f843b7355a0f096aa78e91419b43b99 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Mon, 29 Nov 2021 09:48:05 +0000 Subject: [PATCH] cp ml --- examples/cp/cp.ml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/cp/cp.ml diff --git a/examples/cp/cp.ml b/examples/cp/cp.ml new file mode 100644 index 0000000..a361a00 --- /dev/null +++ b/examples/cp/cp.ml @@ -0,0 +1,30 @@ +open Printf + +let usage_msg = "append [-verbose] [] ... -o " + +let files = ref [] +let anon_fun filename = files := filename::!files + +let () = + Arg.parse [] anon_fun usage_msg; + + let src_file = List.hd !files in + files := List.tl !files; + + let dst_file = List.hd !files in + files := List.tl !files; + + let ic = open_in src_file in + let oc = open_out dst_file in + + + let buf = Bytes.create 4096 in + + let read = ref 4096 in + + while !read > 0 do + (* input ic buf pos len *) + read := input ic buf 0 4096; + (* output oc buf pos len *) + output oc buf 0 !read + done