diff options
author | Damien Doligez <damien.doligez-inria.fr> | 2002-02-25 16:37:15 +0000 |
---|---|---|
committer | Damien Doligez <damien.doligez-inria.fr> | 2002-02-25 16:37:15 +0000 |
commit | f3a1293b03bea85d83213abb8a8824d32f93d02f (patch) | |
tree | 129d4cfb359053bfebb5367dec680f46d304d49b | |
parent | 5dd41d5bc92995a053e19e26b23c99c2a9fb5cac (diff) |
Digest: modif channel, fix PR#924, ajout to_hex
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4437 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rwxr-xr-x | boot/ocamlc | bin | 803845 -> 804070 bytes | |||
-rwxr-xr-x | boot/ocamllex | bin | 89925 -> 89925 bytes | |||
-rw-r--r-- | byterun/md5.c | 20 | ||||
-rw-r--r-- | stdlib/digest.ml | 10 | ||||
-rw-r--r-- | stdlib/digest.mli | 10 | ||||
-rw-r--r-- | stdlib/sys.ml | 2 |
6 files changed, 32 insertions, 10 deletions
diff --git a/boot/ocamlc b/boot/ocamlc Binary files differindex 5c2515d0b..5c743fbd6 100755 --- a/boot/ocamlc +++ b/boot/ocamlc diff --git a/boot/ocamllex b/boot/ocamllex Binary files differindex 7b2171114..d9f7246c8 100755 --- a/boot/ocamllex +++ b/boot/ocamllex diff --git a/byterun/md5.c b/byterun/md5.c index 9acff124e..7e8302674 100644 --- a/byterun/md5.c +++ b/byterun/md5.c @@ -45,12 +45,20 @@ CAMLprim value md5_chan(value vchan, value len) Lock(chan); MD5Init(&ctx); toread = Long_val(len); - while (toread > 0) { - read = getblock(chan, buffer, - toread > sizeof(buffer) ? sizeof(buffer) : toread); - if (read == 0) raise_end_of_file(); - MD5Update(&ctx, (unsigned char *) buffer, read); - toread -= read; + if (toread < 0){ + while (1){ + read = getblock (chan, buffer, sizeof(buffer)); + if (read == 0) break; + MD5Update (&ctx, (unsigned char *) buffer, read); + } + }else{ + while (toread > 0) { + read = getblock(chan, buffer, + toread > sizeof(buffer) ? sizeof(buffer) : toread); + if (read == 0) raise_end_of_file(); + MD5Update(&ctx, (unsigned char *) buffer, read); + toread -= read; + } } res = alloc_string(16); MD5Final(&Byte_u(res, 0), &ctx); diff --git a/stdlib/digest.ml b/stdlib/digest.ml index 15755c31a..29d1295c7 100644 --- a/stdlib/digest.ml +++ b/stdlib/digest.ml @@ -30,7 +30,7 @@ let substring str ofs len = let file filename = let ic = open_in_bin filename in - let d = channel ic (in_channel_length ic) in + let d = channel ic (-1) in close_in ic; d @@ -41,3 +41,11 @@ let input chan = let digest = String.create 16 in really_input chan digest 0 16; digest + +let to_hex d = + let result = String.create 32 in + for i = 0 to 15 do + String.blit (Printf.sprintf "%02x" (int_of_char d.[i])) 0 result (2*i) 2; + done; + result +;; diff --git a/stdlib/digest.mli b/stdlib/digest.mli index bbcf51604..342a3a4ea 100644 --- a/stdlib/digest.mli +++ b/stdlib/digest.mli @@ -33,8 +33,12 @@ val substring : string -> int -> int -> t characters. *) external channel : in_channel -> int -> t = "md5_chan" -(** [Digest.channel ic len] reads [len] characters from channel [ic] - and returns their digest. *) +(** If [len] is nonnegative, [Digest.channel ic len] reads [len] + characters from channel [ic] and returns their digest, or raises + [End_of_file] if end-of-file is reached before [len] characters + are read. If [len] is negative, [Digest.channel ic len] reads + characters from [ic] until end-of-file is reached and return their + digest. *) val file : string -> t (** Return the digest of the file whose name is given. *) @@ -45,3 +49,5 @@ val output : out_channel -> t -> unit val input : in_channel -> t (** Read a digest from the given input channel. *) +val to_hex : t -> string +(** Return the printable hexadecimal representation of the given digest. *) diff --git a/stdlib/sys.ml b/stdlib/sys.ml index 9da1b6c48..3a096399a 100644 --- a/stdlib/sys.ml +++ b/stdlib/sys.ml @@ -78,4 +78,4 @@ let catch_break on = (* OCaml version numbers and strings, moved from utils/config.mlp. Must be in the format described in sys.mli. *) -let ocaml_version = "3.04+6 (2002-02-05)" +let ocaml_version = "3.04+7 (2002-02-25)" |