diff -r c2f4c0285180 -r f600b0d1fc5d bl/textfileutils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bl/textfileutils.c Fri Jan 27 10:30:16 2012 +0000 @@ -0,0 +1,33 @@ +#include +#include +#include + +/* + * Read a file into memory (which should be freed with mem_free when no + * longer required). Returns NULL on error and outputs a suitable error + * message to stderr. + * DOS-style line endings are handled transparently even on platforms which + * don't normally use this format. + */ +boolean file_get_contents_text(const char *filename,char **contents, + size_t *length) +{ + int i; + char *raw; + size_t raw_length; + String *string; + if (!file_get_contents(filename,&raw,&raw_length)) + return FALSE; + string=string_new(NULL); + for(i=0;ilen; + if (contents) + *contents=string_free(string,FALSE); + else + string_free(string,TRUE); + return TRUE; +}