diff options
| author | Brian Campbell | 2017-09-18 16:31:56 +0100 |
|---|---|---|
| committer | Brian Campbell | 2017-09-18 16:31:56 +0100 |
| commit | 4d83d5cf11751b990055963797b5919bf7c22b0b (patch) | |
| tree | 329c2cd838c467430146ceafd662f6a8a7091d40 /lib/ocaml_rts/linksem/byte_sequence_wrapper.ml | |
| parent | d7d7b781e91abbefca7e7a037c4109b3db89f958 (diff) | |
| parent | 4e7a568bb57337d41dda893044ed84b66e62752f (diff) | |
Merge branch 'experiments' into mono-experiments
Diffstat (limited to 'lib/ocaml_rts/linksem/byte_sequence_wrapper.ml')
| -rw-r--r-- | lib/ocaml_rts/linksem/byte_sequence_wrapper.ml | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/ocaml_rts/linksem/byte_sequence_wrapper.ml b/lib/ocaml_rts/linksem/byte_sequence_wrapper.ml new file mode 100644 index 00000000..69efcc8d --- /dev/null +++ b/lib/ocaml_rts/linksem/byte_sequence_wrapper.ml @@ -0,0 +1,33 @@ +open Big_int + +open Error + +let acquire_char_list (fname : string) = + let char_list = ref [] in + try + let ic = open_in_bin fname in + while true do + let c = input_char ic in + let _ = char_list := c :: !char_list in + () + done; + let _ = close_in ic in + Fail "acquire_char_list: the impossible happened" + with End_of_file -> + Success (List.rev !char_list) +;; + +let serialise_char_list (fname : string) bytes = + let rec go oc bytes = + match bytes with + | [] -> () + | x::xs -> output_char oc x; go oc xs + in + try + let oc = open_out_bin fname in + let _ = go oc bytes in + let _ = close_out oc in + Success () + with _ -> + Fail "serialise_char_list: unable to open file for writing" +;;
\ No newline at end of file |
