diff -r 000000000000 -r 218904410231 gclib/textfileutils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gclib/textfileutils.c Fri Jan 27 00:28:11 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; +}