From 2801ddcacc0651da437c8eb537a29338f6432659 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 10 Jan 2002 16:47:58 +0000 Subject: [PATCH] Add 'get' functions. --- lib/config/config.c | 34 +++++++++++++++++++++++++++++----- lib/config/config.h | 14 +++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/config/config.c b/lib/config/config.c index 9e98a74a0..477cb0763 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -632,8 +632,32 @@ int find_config_bool(struct config_node *cn, const char *path, return fail; } -/* - * Local variables: - * c-file-style: "linux" - * End: - */ +int get_config_uint32(struct config_node *cn, const char *path, + char sep, uint32_t *result) +{ + struct config_node *n; + + n = find_config_node(cn, path, sep); + + if (!n || !n->v || n->v->type != CFG_INT) + return 0; + + *result = n->v->v.i; + return 1; +} + +int get_config_uint64(struct config_node *cn, const char *path, + char sep, uint64_t *result) +{ + struct config_node *n; + + n = find_config_node(cn, path, sep); + + if (!n || !n->v || n->v->type != CFG_INT) + return 0; + + /* FIXME Support 64-bit value! */ + *result = (uint64_t) n->v->v.i; + return 1; +} + diff --git a/lib/config/config.h b/lib/config/config.h index 90d10ddbe..8c4fa8672 100644 --- a/lib/config/config.h +++ b/lib/config/config.h @@ -7,6 +7,7 @@ #ifndef _LVM_CONFIG_H #define _LVM_CONFIG_H +#include enum { CFG_STRING, @@ -59,10 +60,13 @@ float find_config_float(struct config_node *cn, const char *path, int find_config_bool(struct config_node *cn, const char *path, char sep, int fail); + + +int get_config_uint32(struct config_node *cn, const char *path, + char sep, uint32_t *result); + +int get_config_uint64(struct config_node *cn, const char *path, + char sep, uint64_t *result); + #endif -/* - * Local variables: - * c-file-style: "linux" - * End: - */