The length parameter for g_file_replace_contents() is a gsize, so -1 is unsuitable here. Just use strlen() directly.