summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2011-01-22 22:38:18 +0000
committerpjd <pjd@FreeBSD.org>2011-01-22 22:38:18 +0000
commit6cd4e3c7deb12c5b2fa63e5ef36fd1a0a8ff0b19 (patch)
treee5b61231474ad29b72332285b9aa3b96d5231384
parent12400e5c9f132a43c62c04ee5afd3cfe8aa25277 (diff)
downloadFreeBSD-src-6cd4e3c7deb12c5b2fa63e5ef36fd1a0a8ff0b19.zip
FreeBSD-src-6cd4e3c7deb12c5b2fa63e5ef36fd1a0a8ff0b19.tar.gz
Add nv_assert() which allows to assert that the given name exists.
MFC after: 1 week
-rw-r--r--sbin/hastd/nv.c30
-rw-r--r--sbin/hastd/nv.h1
2 files changed, 26 insertions, 5 deletions
diff --git a/sbin/hastd/nv.c b/sbin/hastd/nv.c
index aa37fcf..1f994ee 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 664557e..d49fa5d 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_ */
OpenPOWER on IntegriCloud