lua-users home
lua-l archive

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


Dear,

If calculate the entire file is needed, the code can be:

unsigned char block[buf_size]

open_file
md5_init_ctx()
while(!feof)
{
	read_a_block_from_file(block)
	md5_update(block)
}
md5_fini()

If not, you can set a step to skip some data
			 
Aurora
2010-04-27

-------------------------------------------------------------

>> 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.