---
src/util/sexpr.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/sexpr.h | 6 ++++
src/xen/xend_internal.c | 65 -----------------------------------------------
3 files changed, 70 insertions(+), 65 deletions(-)
diff --git a/src/util/sexpr.c b/src/util/sexpr.c
index 330280e..7f14206 100644
--- a/src/util/sexpr.c
+++ b/src/util/sexpr.c
@@ -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;
+}
diff --git a/src/util/sexpr.h b/src/util/sexpr.h
index 04125ea..dc6687d 100644
--- a/src/util/sexpr.h
+++ b/src/util/sexpr.h
@@ -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
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index bc23595..6f98dc0 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -602,71 +602,6 @@ cleanup:
}
/**
- * 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
* @sexpr: an S-Expression
--
libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list