static xmlDocPtr hwloc__libxml2_prepare_export(hwloc_topology_t topology, unsigned long flags) { struct hwloc__xml_export_state_s state; hwloc__libxml_export_state_data_t data = (void *) state.data; xmlDocPtr doc = NULL; /* document pointer */ xmlNodePtr root_node = NULL; /* root pointer */ assert(sizeof(*data) <= sizeof(state.data)); LIBXML_TEST_VERSION; hwloc_libxml2_init_once(); /* Creates a new document, a node and set it as a root node. */ doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "topology"); xmlDocSetRootElement(doc, root_node); /* Creates a DTD declaration. Isn't mandatory. */ (void) xmlCreateIntSubset(doc, BAD_CAST "topology", NULL, BAD_CAST "hwloc.dtd"); state.new_child = hwloc__libxml_export_new_child; state.new_prop = hwloc__libxml_export_new_prop; state.add_content = hwloc__libxml_export_add_content; state.end_object = hwloc__libxml_export_end_object; data->current_node = root_node; hwloc__xml_export_topology (&state, topology, flags); return doc; }
static size_t hwloc___nolibxml_prepare_export(hwloc_topology_t topology, struct hwloc__xml_export_data_s *edata, char *xmlbuffer, int buflen, unsigned long flags) { struct hwloc__xml_export_state_s state, childstate; hwloc__nolibxml_export_state_data_t ndata = (void *) &state.data; int v1export = flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1; int res; HWLOC_BUILD_ASSERT(sizeof(*ndata) <= sizeof(state.data)); state.new_child = hwloc__nolibxml_export_new_child; state.new_prop = hwloc__nolibxml_export_new_prop; state.add_content = hwloc__nolibxml_export_add_content; state.end_object = hwloc__nolibxml_export_end_object; state.global = edata; ndata->indent = 0; ndata->written = 0; ndata->buffer = xmlbuffer; ndata->remaining = buflen; ndata->nr_children = 1; /* don't close a non-existing previous tag when opening the topology tag */ ndata->has_content = 0; res = hwloc_snprintf(ndata->buffer, ndata->remaining, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE topology SYSTEM \"%s\">\n", v1export ? "hwloc.dtd" : "hwloc2.dtd"); hwloc__nolibxml_export_update_buffer(ndata, res); hwloc__nolibxml_export_new_child(&state, &childstate, "topology"); if (!(flags & HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1)) hwloc__nolibxml_export_new_prop(&childstate, "version", "2.0"); hwloc__xml_export_topology (&childstate, topology, flags); hwloc__nolibxml_export_end_object(&childstate, "topology"); return ndata->written+1; /* ending \0 */ }