6 * Read a file into memory (which should be freed with mem_free when no
7 * longer required). Returns NULL on error and outputs a suitable error
9 * DOS-style line endings and UTF-8 BOM are handled transparently even
10 * on platforms which don't normally use these formats.
12 gboolean file_get_contents_text(const char *filename,char **contents,
20 if (!g_file_get_contents(filename,(char *)&raw,&raw_length,&error))
22 fprintf(stderr,"%s: %s\n",filename,error->message);
26 string=g_string_new(NULL);
28 if (raw_length>=3 && raw[0]==0xEF && raw[1]==0xBB && raw[2]==0xBF)
29 i+=3; /* Skip BOM (U+FEFF) */
30 for(;i<raw_length;i++)
32 g_string_append_c(string,raw[i]);
37 *contents=g_string_free(string,FALSE);
39 g_string_free(string,TRUE);