Make the nvlist_next(9) function handle NULL pointer variable.
This simplifies removing the first element from nvlist. Reviewed by: AllanJude Approved by: pjd (mentor)
This commit is contained in:
parent
643ef281cd
commit
89ca10c6e2
@ -28,7 +28,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 4, 2015
|
||||
.Dd Aug 11, 2015
|
||||
.Dt NV 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -410,6 +410,16 @@ The
|
||||
argument can be NULL.
|
||||
Elements may not be removed from the nvlist while traversing it.
|
||||
The nvlist must not be in error state.
|
||||
Note that
|
||||
.Fn nvlist_next
|
||||
will handle
|
||||
.Va cookiep
|
||||
being set to
|
||||
.Dv NULL .
|
||||
In this case first element is returned or
|
||||
.Dv NULL
|
||||
if nvlist is empty.
|
||||
This behavior simplifies removing the first element from the list.
|
||||
.Pp
|
||||
The
|
||||
.Fn nvlist_exists
|
||||
|
@ -1026,9 +1026,8 @@ nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
|
||||
nvpair_t *nvp;
|
||||
|
||||
NVLIST_ASSERT(nvl);
|
||||
PJDLOG_ASSERT(cookiep != NULL);
|
||||
|
||||
if (*cookiep == NULL)
|
||||
if (cookiep == NULL || *cookiep == NULL)
|
||||
nvp = nvlist_first_nvpair(nvl);
|
||||
else
|
||||
nvp = nvlist_next_nvpair(nvl, *cookiep);
|
||||
@ -1036,7 +1035,8 @@ nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
|
||||
return (NULL);
|
||||
if (typep != NULL)
|
||||
*typep = nvpair_type(nvp);
|
||||
*cookiep = nvp;
|
||||
if (cookiep != NULL)
|
||||
*cookiep = nvp;
|
||||
return (nvpair_name(nvp));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user