xml_GNode*
xml_tree_node_from_file (const xml_GNode* mine,
const gchar* file, GError** error)
{
int e;
xml_GNode* node = 0;
if (mine && !mine->text) goto _mine_without_text;
___ int f;
f = open (file, O_RDONLY);
if (f < 0) goto _could_not_open_file_;
___ struct stat st;
e = fstat (f, &st);
if (e < 0) goto _could_not_stat_file_;
___ void* p = mmap (0, st.st_size, PROT_READ, MAP_SHARED, f, 0);
if (p == MAP_FAILED) goto _could_not_mmap_file_;
node = xml_tree_node_from_text (mine, p, 0, st.st_size, file);
if (node->end - node->off != st.st_size) goto _incomplete_read;
_unmap_:
munmap (p, st.st_size);
____;____;
_close_:
close (f);
____;
_return_:
return node;
_mine_without_text:
xml_g_set_error (error, 0, "elder node without text, a bug?");
goto _return_;
_could_not_open_file_:
xml_g_set_error (error, errno, "could not open file: '%s': %s",
file, g_strerror(errno));
goto _return_;
_could_not_stat_file_:
xml_g_set_error (error, errno, "could not stat file: '%s': %s",
file, g_strerror(errno));
goto _close_;
_could_not_mmap_file_:
xml_g_set_error (error, errno, "could not mmap file: '%s': %s",
file, g_strerror(errno));
goto _unmap_;
_incomplete_read:
xml_g_set_error (error, 0, "could not append file '%s' entirely (OOM?)",
file);
goto _unmap_;
} |
|