Add nv_assert() which allows to assert that the given name exists.
MFC after: 1 week
This commit is contained in:
parent
09d6ae1b34
commit
eed4e65fdb
@ -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.
|
||||
*/
|
||||
|
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user