#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; }