From owner-svn-src-head@FreeBSD.ORG Sun Oct 24 17:24:08 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CA360106566B; Sun, 24 Oct 2010 17:24:08 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9E4948FC08; Sun, 24 Oct 2010 17:24:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o9OHO8Hs035034; Sun, 24 Oct 2010 17:24:08 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9OHO8FU035031; Sun, 24 Oct 2010 17:24:08 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201010241724.o9OHO8FU035031@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Sun, 24 Oct 2010 17:24:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214283 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Sun, 24 Oct 2010 17:24:08 -0000 Author: pjd Date: Sun Oct 24 17:24:08 2010 New Revision: 214283 URL: http://svn.freebsd.org/changeset/base/214283 Log: Implement nv_exists() function that returns true if argument of the given name exists. MFC after: 3 days Modified: head/sbin/hastd/nv.c head/sbin/hastd/nv.h Modified: head/sbin/hastd/nv.c ============================================================================== --- head/sbin/hastd/nv.c Sun Oct 24 17:22:34 2010 (r214282) +++ head/sbin/hastd/nv.c Sun Oct 24 17:24:08 2010 (r214283) @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); #include #include +#define NV_TYPE_NONE 0 + #define NV_TYPE_INT8 1 #define NV_TYPE_UINT8 2 #define NV_TYPE_INT16 3 @@ -561,6 +563,29 @@ nv_get_string(struct nv *nv, const char return (str); } +bool +nv_exists(struct nv *nv, const char *namefmt, ...) +{ + struct nvhdr *nvh; + va_list nameap; + int snverror, serrno; + + if (nv == NULL) + return (false); + + serrno = errno; + snverror = nv->nv_error; + + va_start(nameap, namefmt); + nvh = nv_find(nv, NV_TYPE_NONE, namefmt, nameap); + va_end(nameap); + + errno = serrno; + nv->nv_error = snverror; + + return (nvh != NULL); +} + /* * Dump content of the nv structure. */ @@ -797,7 +822,8 @@ nv_find(struct nv *nv, int type, const c assert(size >= NVH_SIZE(nvh)); nv_swap(nvh, true); if (strcmp(nvh->nvh_name, name) == 0) { - if ((nvh->nvh_type & NV_TYPE_MASK) != type) { + if (type != NV_TYPE_NONE && + (nvh->nvh_type & NV_TYPE_MASK) != type) { errno = EINVAL; if (nv->nv_error == 0) nv->nv_error = EINVAL; Modified: head/sbin/hastd/nv.h ============================================================================== --- head/sbin/hastd/nv.h Sun Oct 24 17:22:34 2010 (r214282) +++ head/sbin/hastd/nv.h Sun Oct 24 17:24:08 2010 (r214283) @@ -126,6 +126,7 @@ const uint64_t *nv_get_uint64_array(stru const char *nv_get_string(struct nv *nv, const char *namefmt, ...) __printflike(2, 3); +bool nv_exists(struct nv *nv, const char *namefmt, ...) __printflike(2, 3); void nv_dump(struct nv *nv); #endif /* !_NV_H_ */