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

Re: md5sum'ing a string buffer: questions regarding buffer code



Hi!

On Thu, 2009-09-24 at 09:11:24 +0200, sean finney wrote:
> previously, i had this function to create the md5sum of a filename:
> 
> /* calculate the md5sum of the contents of the null-terminated string input 
>  * putting the result in output, which will be allocated with memory to
>  * store the result.  your job to free it later.
>  */
> static void conff_md5sum_str(const char *input, char **output){
[...]
> }
> 
> but this "proc" member has disappeared during the refactoring/move
> of the buffer code.  this leaves me with only the existing macros for
> dealing with buffers, and none of the existing macros seem to support using a
> pointer-to-memory at the source end.
> 
> i can think up two solutions off the top of my head, and i'm wondering
> what you think:
> 
>  * pipe() an fd pair and write filename into it, and then call fd_md5().
>    seems like a hack, but if it worked it would avoid requiring changes to
>    the buffer code (i don't know if the buffer code makes any assumptions
>    about the fd that this might break though).
>  * define a new BUFFER_READ_BUF value and then modify the buffer routines
>    to support this value with a memcpy from the source pointer.  more general
>    but it's not clear that it'd be generally useful.
> 
> what would you suggest?  it's also possible that i'm missing some other way
> to do this (ideally not manually), so i'd appreciate to know that as well :)

As adding a BUFFER_READ_BUF would have implied copying the contents of
the buffer around more than need, I've now created a new buffer_hash
function and the corresponding buffer_md5 macro. Take into account
BUFFER_WRITE_MD5 no longer allocates a buffer for you.

I'm still not happy with the buffer API though, and will be reworking it
in the future, probably by also combining the compression API into it.

regards,
guillem


Reply to: