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:
Mariusz Zaborski 2015-08-11 17:41:32 +00:00
parent 643ef281cd
commit 89ca10c6e2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286642
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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));
}