#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. */ gboolean file_get_contents_text(const char *filename,char **contents, size_t *length) { int i; char *raw; size_t raw_length; GString *string; GError *error=NULL; if (!g_file_get_contents(filename,&raw,&raw_length,&error)) { fprintf(stderr,"%s: %s\n",filename,error->message); g_error_free(error); return FALSE; } string=g_string_new(NULL); for(i=0;ilen; if (contents) *contents=g_string_free(string,FALSE); else g_string_free(string,TRUE); return TRUE; }