Author: oshogbo
Date: Tue Aug 11 17:41:32 2015
New Revision: 286642
URL: https://svnweb.freebsd.org/changeset/base/286642

Log:
  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)

Modified:
  head/share/man/man9/nv.9
  head/sys/contrib/libnv/nvlist.c

Modified: head/share/man/man9/nv.9
==============================================================================
--- head/share/man/man9/nv.9    Tue Aug 11 17:24:34 2015        (r286641)
+++ head/share/man/man9/nv.9    Tue Aug 11 17:41:32 2015        (r286642)
@@ -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

Modified: head/sys/contrib/libnv/nvlist.c
==============================================================================
--- head/sys/contrib/libnv/nvlist.c     Tue Aug 11 17:24:34 2015        
(r286641)
+++ head/sys/contrib/libnv/nvlist.c     Tue Aug 11 17:41:32 2015        
(r286642)
@@ -1026,9 +1026,8 @@ nvlist_next(const nvlist_t *nvl, int *ty
        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 *ty
                return (NULL);
        if (typep != NULL)
                *typep = nvpair_type(nvp);
-       *cookiep = nvp;
+       if (cookiep != NULL)
+               *cookiep = nvp;
        return (nvpair_name(nvp));
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to