/* Contrary to caml_md5_chan, this function releases the runtime lock. [fd] must be a file descriptor open for reading and not be nonblocking, otherwise the function might fail non-deterministically. */ CAMLprim value caml_md5_fd(value fd) { CAMLparam1 (fd); value res; struct MD5Context ctx; caml_enter_blocking_section(); { intnat bytes_read; char buffer[4096]; caml_MD5Init(&ctx); while (1){ bytes_read = read (Int_val(fd), buffer, sizeof(buffer)); if (bytes_read < 0) { if (errno == EINTR) continue; caml_leave_blocking_section(); uerror("caml_md5_fd", Nothing); } if (bytes_read == 0) break; caml_MD5Update (&ctx, (unsigned char *) buffer, bytes_read); } } caml_leave_blocking_section(); res = caml_alloc_string(16); caml_MD5Final(&Byte_u(res, 0), &ctx); CAMLreturn (res); }
CAMLprim value caml_md5_update(value ctx, value src, value ofs, value len) { caml_MD5Update(Context_val(ctx), &Byte_u(src, Long_val(ofs)), Long_val(len)); return Val_unit; }