Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common Add prop_array_add_cstring{, _no_copy} utility functio...
details: https://anonhg.NetBSD.org/src/rev/2440ba74cbbb
branches: trunk
changeset: 345531:2440ba74cbbb
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Tue May 31 09:29:25 2016 +0000
description:
Add prop_array_add_cstring{,_no_copy} utility functions as suggested in
PR lib/46723 using the patch provided. (Header file updates are mine.)
diffstat:
common/include/prop/prop_array.h | 4 +++-
common/lib/libprop/prop_array_util.3 | 17 +++++++++++++----
common/lib/libprop/prop_array_util.c | 17 ++++++++++++++++-
3 files changed, 32 insertions(+), 6 deletions(-)
diffs (121 lines):
diff -r c6a8092cb9fb -r 2440ba74cbbb common/include/prop/prop_array.h
--- a/common/include/prop/prop_array.h Tue May 31 09:22:11 2016 +0000
+++ b/common/include/prop/prop_array.h Tue May 31 09:29:25 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prop_array.h,v 1.13 2011/09/30 22:08:18 jym Exp $ */
+/* $NetBSD: prop_array.h,v 1.14 2016/05/31 09:29:25 pgoyette Exp $ */
/*-
* Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
@@ -144,11 +144,13 @@
bool prop_array_add_int64(prop_array_t, int64_t);
bool prop_array_add_uint64(prop_array_t, uint64_t);
+bool prop_array_add_cstring(prop_array_t, const char *);
bool prop_array_get_cstring(prop_array_t, unsigned int,
char **);
bool prop_array_set_cstring(prop_array_t, unsigned int,
const char *);
+bool prop_array_add_cstring_nocopy(prop_array_t, const char *);
bool prop_array_get_cstring_nocopy(prop_array_t,
unsigned int,
const char **);
diff -r c6a8092cb9fb -r 2440ba74cbbb common/lib/libprop/prop_array_util.3
--- a/common/lib/libprop/prop_array_util.3 Tue May 31 09:22:11 2016 +0000
+++ b/common/lib/libprop/prop_array_util.3 Tue May 31 09:29:25 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: prop_array_util.3,v 1.7 2011/10/17 09:24:54 wiz Exp $
+.\" $NetBSD: prop_array_util.3,v 1.8 2016/05/31 09:29:25 pgoyette Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd March 12, 2011
+.Dd May 31, 2016
.Dt PROP_ARRAY_UTIL 3
.Os
.Sh NAME
@@ -58,8 +58,10 @@
.Nm prop_array_add_uint32 ,
.Nm prop_array_add_int64 ,
.Nm prop_array_add_uint64 ,
+.Nm prop_array_add_cstring ,
.Nm prop_array_get_cstring ,
.Nm prop_array_set_cstring ,
+.Nm prop_array_add_cstring_nocopy ,
.Nm prop_array_get_cstring_nocopy ,
.Nm prop_array_set_cstring_nocopy ,
.Nm prop_array_add_and_rel
@@ -153,6 +155,8 @@
.Fn prop_array_add_uint64 "prop_array_t dict" "uint64_t val"
.\"
.Ft bool
+.Fn prop_array_add_cstring "prop_array_t dict" "const char *cp"
+.Ft bool
.Fn prop_array_get_cstring "prop_array_t dict" "unsigned int indx" \
"char **strp"
.Ft bool
@@ -160,6 +164,8 @@
"const char *str"
.\"
.Ft bool
+.Fn prop_array_add_cstring_nocopy "prop_array_t dict" "const char *cp"
+.Ft bool
.Fn prop_array_get_cstring_nocopy "prop_array_t dict" \
"unsigned int indx" "const char **strp"
.Ft bool
@@ -181,14 +187,17 @@
The setters handle object creation and release for the caller.
.Pp
The
+.Fn prop_array_add_cstring
+and
.Fn prop_array_get_cstring
-function returns dynamically allocated memory.
+functions returns dynamically allocated memory.
See
.Xr prop_string 3
for more information.
.Pp
The
-.Fn prop_array_get_cstring_nocopy
+.Fn prop_array_add_cstring_nocopy,
+.Fn prop_array_get_cstring_nocopy,
and
.Fn prop_array_set_cstring_nocopy
functions do not copy the string that is set or returned.
diff -r c6a8092cb9fb -r 2440ba74cbbb common/lib/libprop/prop_array_util.c
--- a/common/lib/libprop/prop_array_util.c Tue May 31 09:22:11 2016 +0000
+++ b/common/lib/libprop/prop_array_util.c Tue May 31 09:29:25 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prop_array_util.c,v 1.4 2012/07/27 09:10:59 pooka Exp $ */
+/* $NetBSD: prop_array_util.c,v 1.5 2016/05/31 09:29:25 pgoyette Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -201,6 +201,21 @@
#undef TEMPLATE
#define TEMPLATE(variant, qualifier) \
+bool \
+prop_array_add_cstring ## variant (prop_array_t array, \
+ const char *cp) \
+{ \
+ prop_string_t str; \
+ bool rv; \
+ \
+ str = prop_string_create_cstring ## variant (cp); \
+ if (str == NULL) \
+ return false; \
+ rv = prop_array_add(array, str); \
+ prop_object_release(str); \
+ return rv; \
+} \
+ \
bool \
prop_array_get_cstring ## variant (prop_array_t array, \
unsigned int indx, \
Home |
Main Index |
Thread Index |
Old Index