rust: prevent dead_code warning
[nbdkit.git] / tests / cc_shebang.ml
blobd78d76618412b2be7d24bfe2be0a968bd8a74617
1 (*/.)>/dev/null 2>&1
3 # The above line is parsed by OCaml as an opening comment and by the
4 # shell as an impossible command which is ignored. The line below is
5 # run by the shell and ignored by OCaml.
7 exec nbdkit cc "$0" CC=ocamlopt CFLAGS="-output-obj -runtime-variant _pic unix.cmxa NBDKit.cmx -cclib -lnbdkitocaml" "$@"
8 *)
10 open Printf
12 let disk = ref (Bytes.make (1024*1024) '\000')
14 let config k v =
15 match k with
16 | "size" ->
17 let size = NBDKit.parse_size v in
18 let size = Int64.to_int size in
19 disk := Bytes.make size '\000'
20 | _ ->
21 failwith (sprintf "unknown parameter: %s" k)
23 let open_connection _ = ()
25 let get_size () = Bytes.length !disk |> Int64.of_int
27 let pread () count offset _ =
28 let buf = Bytes.create count in
29 Bytes.blit !disk (Int64.to_int offset) buf 0 count;
30 Bytes.unsafe_to_string buf
32 let pwrite () buf offset _ =
33 let len = String.length buf in
34 let offset = Int64.to_int offset in
35 String.blit buf 0 !disk offset len
37 let () =
38 NBDKit.register_plugin
39 ~name: "cc-shebang.ml"
40 ~version: (NBDKit.version ())
41 ~config
42 ~open_connection
43 ~get_size
44 ~pread
45 ~pwrite