From 23c5a51e92dfe00ea297be0caff1ff2ec9fe4c93 Mon Sep 17 00:00:00 2001 From: Mariusz Zaborski Date: Thu, 26 Oct 2017 20:44:42 +0000 Subject: [PATCH] Introduce cnvlist_name() and cnvlist_type() functions. Those function can be used when we are iterating over nvlist to reduce amount of extra variables we need to declare. MFC after: 1 month --- share/man/man9/cnv.9 | 17 ++++++++++++++++- sys/contrib/libnv/cnvlist.c | 14 ++++++++++++++ sys/sys/cnv.h | 6 ++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/share/man/man9/cnv.9 b/share/man/man9/cnv.9 index 453cbee0456..fef921488bd 100644 --- a/share/man/man9/cnv.9 +++ b/share/man/man9/cnv.9 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 27, 2016 +.Dd October 26, 2017 .Dt CNV 9 .Os .Sh NAME @@ -37,6 +37,11 @@ .Lb libnv .Sh SYNOPSIS .In sys/cnv.h +.Ft const char * +.Fn cnvlist_name "void *cookiep" +.Ft int +.Fn cnvlist_type "void *cookiep" +.\" .Ft bool .Fn cnvlist_get_bool "void *cookiep" .Ft uint64_t @@ -124,6 +129,16 @@ from .Xr nv 9 . .Pp The +.Fn cnvlist_name +function returns the name of an element associated with the given cookie. +.Pp +The +.Fn cnvlist_type +function returns the type of an element associated with the given cookie. +Types which can be returned are described in +.Xr nv 9 . +.Pp +The .Nm cnvlist_get family of functions obtains the value associated with the given cookie. Returned strings, nvlists, descriptors, binaries, or arrays must not be modified diff --git a/sys/contrib/libnv/cnvlist.c b/sys/contrib/libnv/cnvlist.c index 0886da69674..aff1c8e612e 100644 --- a/sys/contrib/libnv/cnvlist.c +++ b/sys/contrib/libnv/cnvlist.c @@ -53,6 +53,20 @@ __FBSDID("$FreeBSD$"); #include "nvlist_impl.h" #include "nvpair_impl.h" +const char * +cnvlist_name(void *cookiep) +{ + + return (nvpair_name(cookiep)); +} + +int +cnvlist_type(void *cookiep) +{ + + return (nvpair_type(cookiep)); +} + #define CNVLIST_GET(ftype, type, NVTYPE) \ ftype \ cnvlist_get_##type(void *cookiep) \ diff --git a/sys/sys/cnv.h b/sys/sys/cnv.h index 8b76e596bf2..c89eed37df3 100644 --- a/sys/sys/cnv.h +++ b/sys/sys/cnv.h @@ -47,6 +47,12 @@ typedef struct nvlist nvlist_t; __BEGIN_DECLS +/* + * Functions which returns information about the given cookie. + */ +const char *cnvlist_name(void *cookiep); +int cnvlist_type(void *cookiep); + /* * The cnvlist_get functions returns value associated with the given cookie. * If it returns a pointer, the pointer represents internal buffer and should