提交 ee197521 编写于 作者: M Mark McLoughlin

Add virXPathULongLong()

Add a variant of virXPathULong() which can handle long longs.

Needed for parsing storage device capacities.
上级 c56b4bcb
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()
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册