mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
Moved some SEXPR functions from xen-unified
This commit is contained in:
parent
8606ca0d0b
commit
c71328b9aa
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user