summaryrefslogtreecommitdiffstats
path: root/byterun/md5.c
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2002-02-25 16:37:15 +0000
committerDamien Doligez <damien.doligez-inria.fr>2002-02-25 16:37:15 +0000
commitf3a1293b03bea85d83213abb8a8824d32f93d02f (patch)
tree129d4cfb359053bfebb5367dec680f46d304d49b /byterun/md5.c
parent5dd41d5bc92995a053e19e26b23c99c2a9fb5cac (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
Diffstat (limited to 'byterun/md5.c')
-rw-r--r--byterun/md5.c20
1 files changed, 14 insertions, 6 deletions
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);