diff --git a/share/man/man9/nv.9 b/share/man/man9/nv.9 index 8c4bb2095c1..e3d70801117 100644 --- a/share/man/man9/nv.9 +++ b/share/man/man9/nv.9 @@ -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 diff --git a/sys/contrib/libnv/nvlist.c b/sys/contrib/libnv/nvlist.c index 3138001eab4..cdb54d28f48 100644 --- a/sys/contrib/libnv/nvlist.c +++ b/sys/contrib/libnv/nvlist.c @@ -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)); }