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
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=217732
2 changed files with 26 additions and 5 deletions

View File

@ -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.
*/

View File

@ -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_ */