mirror of https://gitee.com/openkylin/libvirt.git
Add virXPathULongLong()
Add a variant of virXPathULong() which can handle long longs. Needed for parsing storage device capacities.
This commit is contained in:
parent
c56b4bcbf3
commit
ee197521c5
|
@ -1,3 +1,7 @@
|
|||
Tue Feb 24 14:52:58 GMT 2009 Mark McLoughlin <markmc@redhat.com>
|
||||
|
||||
* src/xml.[ch]: Add virXPathULongLong()
|
||||
|
||||
Tue Feb 24 14:52:44 GMT 2009 Mark McLoughlin <markmc@redhat.com>
|
||||
|
||||
* src/xml.[ch]: Add virXPathLongHex() and virXPathULongHex()
|
||||
|
|
55
src/xml.c
55
src/xml.c
|
@ -290,6 +290,61 @@ virXPathULongHex(virConnectPtr conn,
|
|||
return virXPathULongBase(conn, xpath, ctxt, 16, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* virXPathULongLong:
|
||||
* @xpath: the XPath string to evaluate
|
||||
* @ctxt: an XPath context
|
||||
* @value: the returned long long value
|
||||
*
|
||||
* Convenience function to evaluate an XPath number
|
||||
*
|
||||
* Returns 0 in case of success in which case @value is set,
|
||||
* or -1 if the XPath evaluation failed or -2 if the
|
||||
* value doesn't have a long format.
|
||||
*/
|
||||
int
|
||||
virXPathULongLong(virConnectPtr conn,
|
||||
const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long long *value)
|
||||
{
|
||||
xmlXPathObjectPtr obj;
|
||||
xmlNodePtr relnode;
|
||||
int ret = 0;
|
||||
|
||||
if ((ctxt == NULL) || (xpath == NULL) || (value == NULL)) {
|
||||
virXMLError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("Invalid parameter to virXPathULong()"));
|
||||
return (-1);
|
||||
}
|
||||
relnode = ctxt->node;
|
||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
|
||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
|
||||
char *conv = NULL;
|
||||
unsigned long long val;
|
||||
|
||||
val = strtoull((const char *) obj->stringval, &conv, 10);
|
||||
if (conv == (const char *) obj->stringval) {
|
||||
ret = -2;
|
||||
} else {
|
||||
*value = val;
|
||||
}
|
||||
} else if ((obj != NULL) && (obj->type == XPATH_NUMBER) &&
|
||||
(!(isnan(obj->floatval)))) {
|
||||
*value = (unsigned long long) obj->floatval;
|
||||
if (*value != obj->floatval) {
|
||||
ret = -2;
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
xmlXPathFreeObject(obj);
|
||||
ctxt->node = relnode;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char *
|
||||
virXMLPropString(xmlNodePtr node,
|
||||
const char *name)
|
||||
|
|
|
@ -29,6 +29,10 @@ int virXPathULong (virConnectPtr conn,
|
|||
const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long *value);
|
||||
int virXPathULongLong(virConnectPtr conn,
|
||||
const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
unsigned long long *value);
|
||||
int virXPathLongHex (virConnectPtr conn,
|
||||
const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
|
|
Loading…
Reference in New Issue