blob: 2fdcacc8398f399d20d41f6912670dbf5031372c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
let get_content file =
let ic = open_in_bin file in
let buf = Buffer.create 2048 in
let rec fill () =
match input_char ic with
| '\r' -> fill () (* NOTE: handles the case on Windows where the
git checkout has included return characters.
See: https://github.com/coq/coq/pull/6305 *)
| c -> Buffer.add_char buf c; fill ()
| exception End_of_file -> close_in ic; Buffer.contents buf
in
fill ()
let () =
match Sys.argv with
| [|_; file|] ->
let content = get_content file in
let md5 = Digest.to_hex (Digest.string content) in
print_string (md5 ^ " " ^ file)
| _ ->
prerr_endline "Error: This program needs exactly one parameter.";
prerr_endline "Usage: ocaml md5sum.ml <FILE>";
prerr_endline "Print MD5 (128-bit) checksum of the file content modulo \\r.";
exit 1
|