lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> My version of lmd5 has this useful function.  It calculates the MD5 of 
> an entire file and does so from C code.

Allow me some suggestions for that code: 
 
>     const size_t BLOCK_SIZE = 32768;
>     unsigned char* buffer;

Use a fixed buffer of size BUFSIZ.  No need to malloc anything.
fread buffers data anyway. No need to buffer it more than that.

>     fseek(file, 0, SEEK_END);

Just read until fread returns zero. If you want to check for errors,
call ferror at the end.