提交 c71328b9 编写于 作者: M Markus Groß 提交者: Eric Blake

Moved some SEXPR functions from xen-unified

上级 8606ca0d
......@@ -566,3 +566,67 @@ sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
return sexpr_node(sexpr, node);
}
/**
* sexpr_int:
* @sexpr: an S-Expression
* @name: the name for the value
*
* convenience function to lookup an int value in the S-Expression
*
* Returns the value found or 0 if not found (but may not be an error).
* This function suffers from the flaw that zero is both a correct
* return value and an error indicator: careful!
*/
int
sexpr_int(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
if (value) {
return strtol(value, NULL, 0);
}
return 0;
}
/**
* sexpr_float:
* @sexpr: an S-Expression
* @name: the name for the value
*
* convenience function to lookup a float value in the S-Expression
*
* Returns the value found or 0 if not found (but may not be an error)
*/
double
sexpr_float(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
if (value) {
return strtod(value, NULL);
}
return 0;
}
/**
* sexpr_u64:
* @sexpr: an S-Expression
* @name: the name for the value
*
* convenience function to lookup a 64bits unsigned int value in the
* S-Expression
*
* Returns the value found or 0 if not found (but may not be an error)
*/
uint64_t
sexpr_u64(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
if (value) {
return strtoll(value, NULL, 0);
}
return 0;
}
......@@ -16,6 +16,7 @@
# include "internal.h"
# include <sys/types.h>
# include <stdint.h>
enum sexpr_type {
SEXPR_NIL,
......@@ -52,4 +53,9 @@ const char *sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
ATTRIBUTE_FMT_PRINTF(2,3);
struct sexpr *sexpr_lookup(const struct sexpr *sexpr, const char *node);
int sexpr_has(const struct sexpr *sexpr, const char *node);
int sexpr_int(const struct sexpr *sexpr, const char *name);
double sexpr_float(const struct sexpr *sexpr, const char *name);
uint64_t sexpr_u64(const struct sexpr *sexpr, const char *name);
#endif
......@@ -601,71 +601,6 @@ cleanup:
return res;
}
/**
* sexpr_int:
* @sexpr: an S-Expression
* @name: the name for the value
*
* convenience function to lookup an int value in the S-Expression
*
* Returns the value found or 0 if not found (but may not be an error).
* This function suffers from the flaw that zero is both a correct
* return value and an error indicator: careful!
*/
static int
sexpr_int(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
if (value) {
return strtol(value, NULL, 0);
}
return 0;
}
/**
* sexpr_float:
* @sexpr: an S-Expression
* @name: the name for the value
*
* convenience function to lookup a float value in the S-Expression
*
* Returns the value found or 0 if not found (but may not be an error)
*/
static double
sexpr_float(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
if (value) {
return strtod(value, NULL);
}
return 0;
}
/**
* sexpr_u64:
* @sexpr: an S-Expression
* @name: the name for the value
*
* convenience function to lookup a 64bits unsigned int value in the
* S-Expression
*
* Returns the value found or 0 if not found (but may not be an error)
*/
static uint64_t
sexpr_u64(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
if (value) {
return strtoll(value, NULL, 0);
}
return 0;
}
/**
* sexpr_uuid:
* @ptr: where to store the UUID, incremented
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册