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

md5sum'ing a string buffer: questions regarding buffer code

hi guys,

*almost* done with the rebase/squash/split stuff for the conffile database
changes, but now i've stumbled into a problem on which i think i should
get a bit of feedback.  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){
	buffer_arg arg = { (void*) output };
	struct buffer_data data = { buffer_write, arg, BUFFER_WRITE_MD5 };
	data.proc(&data, NULL, 0, "conff_md5sum_str");
	data.proc(&data, (void*)input, strlen(input), "conff_md5sum_str");
	data.proc(&data, NULL, 0, "conff_md5sum_str");

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 :)


Attachment: signature.asc
Description: Digital signature

Reply to: