From 6cd4e3c7deb12c5b2fa63e5ef36fd1a0a8ff0b19 Mon Sep 17 00:00:00 2001 From: pjd Date: Sat, 22 Jan 2011 22:38:18 +0000 Subject: [PATCH] Add nv_assert() which allows to assert that the given name exists. MFC after: 1 week --- sbin/hastd/nv.c | 30 +++++++++++++++++++++++++----- sbin/hastd/nv.h | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/sbin/hastd/nv.c b/sbin/hastd/nv.c index aa37fcf2ec18..1f994ee8b901 100644 --- a/sbin/hastd/nv.c +++ b/sbin/hastd/nv.c @@ -563,11 +563,10 @@ nv_get_string(struct nv *nv, const char *namefmt, ...) return (str); } -bool -nv_exists(struct nv *nv, const char *namefmt, ...) +static bool +nv_vexists(struct nv *nv, const char *namefmt, va_list nameap) { struct nvhdr *nvh; - va_list nameap; int snverror, serrno; if (nv == NULL) @@ -576,9 +575,7 @@ nv_exists(struct nv *nv, const char *namefmt, ...) serrno = errno; snverror = nv->nv_error; - va_start(nameap, namefmt); nvh = nv_find(nv, NV_TYPE_NONE, namefmt, nameap); - va_end(nameap); errno = serrno; nv->nv_error = snverror; @@ -586,6 +583,29 @@ nv_exists(struct nv *nv, const char *namefmt, ...) return (nvh != NULL); } +bool +nv_exists(struct nv *nv, const char *namefmt, ...) +{ + va_list nameap; + bool ret; + + va_start(nameap, namefmt); + ret = nv_vexists(nv, namefmt, nameap); + va_end(nameap); + + return (ret); +} + +void +nv_assert(struct nv *nv, const char *namefmt, ...) +{ + va_list nameap; + + va_start(nameap, namefmt); + assert(nv_vexists(nv, namefmt, nameap)); + va_end(nameap); +} + /* * Dump content of the nv structure. */ diff --git a/sbin/hastd/nv.h b/sbin/hastd/nv.h index 664557ec3441..d49fa5d579f9 100644 --- a/sbin/hastd/nv.h +++ b/sbin/hastd/nv.h @@ -127,6 +127,7 @@ const char *nv_get_string(struct nv *nv, const char *namefmt, ...) __printflike(2, 3); bool nv_exists(struct nv *nv, const char *namefmt, ...) __printflike(2, 3); +void nv_assert(struct nv *nv, const char *namefmt, ...) __printflike(2, 3); void nv_dump(struct nv *nv); #endif /* !_NV_H_ */