From owner-svn-src-head@freebsd.org Tue Aug 11 17:41:33 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8FC0899F415; Tue, 11 Aug 2015 17:41:33 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6634DEDD; Tue, 11 Aug 2015 17:41:33 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7BHfXsI050705; Tue, 11 Aug 2015 17:41:33 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7BHfW3M050703; Tue, 11 Aug 2015 17:41:32 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201508111741.t7BHfW3M050703@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Tue, 11 Aug 2015 17:41:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286642 - in head: share/man/man9 sys/contrib/libnv X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Aug 2015 17:41:33 -0000 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)); }