build: fix build with older libxml2

On RHEL 5, with libxml2-2.6.26, the build failed with:
virsh.c: In function 'vshNodeIsSuperset':
virsh.c:11951: warning: implicit declaration of function 'xmlChildElementCount'

(or if warnings aren't errors, a link failure later on).

* src/util/xml.h (virXMLChildElementCount): New prototype.
* src/util/xml.c (virXMLChildElementCount): New function.
* src/libvirt_private.syms (xml.h): Export it.
* tools/virsh.c (vshNodeIsSuperset): Use it.
This commit is contained in:
Eric Blake 2011-12-07 15:06:18 -07:00 committed by Daniel Veillard
parent e970863746
commit f59a941757
4 changed files with 27 additions and 4 deletions

View File

@ -1400,6 +1400,7 @@ virTimeStringThenRaw;
# xml.h
virXMLChildElementCount;
virXMLParseHelper;
virXMLPropString;
virXMLSaveFile;

View File

@ -833,3 +833,23 @@ virXMLSaveFile(const char *path,
return virFileRewrite(path, S_IRUSR | S_IWUSR, virXMLRewriteFile, &data);
}
/* Returns the number of children of node, or -1 on error. */
long
virXMLChildElementCount(xmlNodePtr node)
{
long ret = 0;
xmlNodePtr cur = NULL;
/* xmlChildElementCount returns 0 on error, which isn't helpful;
* besides, it is not available in libxml2 2.6. */
if (!node || node->type != XML_ELEMENT_NODE)
return -1;
cur = node->children;
while (cur) {
if (cur->type == XML_ELEMENT_NODE)
ret++;
cur = cur->next;
}
return ret;
}

View File

@ -52,6 +52,7 @@ int virXPathNodeSet(const char *xpath,
xmlNodePtr **list);
char * virXMLPropString(xmlNodePtr node,
const char *name);
long virXMLChildElementCount(xmlNodePtr node);
/* Internal function; prefer the macros below. */
xmlDocPtr virXMLParseHelper(int domcode,

View File

@ -11919,7 +11919,7 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
bool found;
bool visited;
bool ret = false;
unsigned long n1_child_size, n2_child_size, n1_iter;
long n1_child_size, n2_child_size, n1_iter;
virBitmapPtr bitmap;
if (!n1 && !n2)
@ -11948,9 +11948,10 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
attr = attr->next;
}
n1_child_size = xmlChildElementCount(n1);
n2_child_size = xmlChildElementCount(n2);
if (n1_child_size < n2_child_size)
n1_child_size = virXMLChildElementCount(n1);
n2_child_size = virXMLChildElementCount(n2);
if (n1_child_size < 0 || n2_child_size < 0 ||
n1_child_size < n2_child_size)
return false;
if (n1_child_size == 0 && n2_child_size == 0)