Add nv_assert() which allows to assert that the given name exists.

MFC after:	1 week
This commit is contained in:
Pawel Jakub Dawidek
2011-01-22 22:38:18 +00:00
parent 09d6ae1b34
commit eed4e65fdb
2 changed files with 26 additions and 5 deletions
+25 -5
View File
@@ -563,11 +563,10 @@ nv_get_string(struct nv *nv, const char *namefmt, ...)
return (str); return (str);
} }
bool static bool
nv_exists(struct nv *nv, const char *namefmt, ...) nv_vexists(struct nv *nv, const char *namefmt, va_list nameap)
{ {
struct nvhdr *nvh; struct nvhdr *nvh;
va_list nameap;
int snverror, serrno; int snverror, serrno;
if (nv == NULL) if (nv == NULL)
@@ -576,9 +575,7 @@ nv_exists(struct nv *nv, const char *namefmt, ...)
serrno = errno; serrno = errno;
snverror = nv->nv_error; snverror = nv->nv_error;
va_start(nameap, namefmt);
nvh = nv_find(nv, NV_TYPE_NONE, namefmt, nameap); nvh = nv_find(nv, NV_TYPE_NONE, namefmt, nameap);
va_end(nameap);
errno = serrno; errno = serrno;
nv->nv_error = snverror; nv->nv_error = snverror;
@@ -586,6 +583,29 @@ nv_exists(struct nv *nv, const char *namefmt, ...)
return (nvh != NULL); 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. * Dump content of the nv structure.
*/ */
+1
View File
@@ -127,6 +127,7 @@ const char *nv_get_string(struct nv *nv, const char *namefmt, ...)
__printflike(2, 3); __printflike(2, 3);
bool nv_exists(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); void nv_dump(struct nv *nv);
#endif /* !_NV_H_ */ #endif /* !_NV_H_ */