Copyright (c) 2006, 2025 The NetBSD Foundation, Inc.
All rights reserved.
This code is derived from software contributed to The NetBSD Foundation
by Jason R. Thorpe.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
.Dd April 20, 2025 .Dt PROP_OBJECT 3 .Os .Sh NAME .Nm prop_object , .Nm prop_object_retain , .Nm prop_object_release , .Nm prop_object_type , .Nm prop_object_equals , .Nm prop_object_iterator_next , .Nm prop_object_iterator_reset , .Nm prop_object_iterator_release , .Nm prop_object_externalize , .Nm prop_object_externalize_with_format , .Nm prop_object_externalize_to_file , .Nm prop_object_externalize_to_file_with_format , .Nm prop_object_internalize , .Nm prop_object_internalize_from_file .Nd general property container object functions .Sh LIBRARY .Lb libprop .Sh SYNOPSIS n prop/proplib.h
.Ft void .Fn prop_object_retain "prop_object_t obj" .Ft void .Fn prop_object_release "prop_object_t obj"
.Ft prop_type_t .Fn prop_object_type "prop_object_t obj" .Ft bool .Fn prop_object_equals "prop_object_t obj1" "prop_object_t obj2"
.Ft prop_object_t .Fn prop_object_iterator_next "prop_object_iterator_t iter" .Ft void .Fn prop_object_iterator_reset "prop_object_iterator_t iter" .Ft void .Fn prop_object_iterator_release "prop_object_iterator_t iter"
.Ft char * .Fn prop_object_externalize "prop_object_t obj" .Ft char * .Fn prop_object_externalize_with_format "prop_object_t obj" \ "prop_format_t format" .Ft bool .Fn prop_object_externalize_to_file "prop_object_t obj" "const char *path" .Ft bool .Fn prop_object_externalize_to_file_with_format "prop_object_t obj" \ "const char *path" "prop_format_t format"
.Ft prop_object_t .Fn prop_object_internalize "const char *data" .Ft prop_object_t .Fn prop_object_internalize_from_file "const char *path" .Sh DESCRIPTION The .Nm family of functions operate on all property container object types. l -tag -width "" t Fn prop_object_retain "prop_object_t obj" Increment the reference count on an object. t Fn prop_object_release "prop_object_t obj" Decrement the reference count on an object. If the last reference is dropped, the object is freed. t Fn prop_object_type "prop_object_t obj" Determine the type of the object. Objects are one of the following types:
p l -tag -width "PROP_TYPE_DICT_KEYSYM" -compact t Dv PROP_TYPE_BOOL Boolean value
q prop_bool_t t Dv PROP_TYPE_NUMBER Number
q prop_number_t t Dv PROP_TYPE_STRING String
q prop_string_t t Dv PROP_TYPE_DATA Opaque data
q prop_data_t t Dv PROP_TYPE_ARRAY Array
q prop_array_t t Dv PROP_TYPE_DICTIONARY Dictionary
q prop_dictionary_t t Dv PROP_TYPE_DICT_KEYSYM Dictionary key symbol
q prop_dictionary_keysym_t .El
p If .Fa obj is .Dv NULL , then .Dv PROP_TYPE_UNKNOWN is returned. t Fn prop_object_equals "prop_object_t obj1" "prop_object_t obj2" Returns .Dv true if the two objects are of the same type and are equivalent. t Fn prop_object_iterator_next "prop_object_iterator_t iter" Return the next object in the collection
q array or dictionary being iterated by the iterator .Fa iter . If there are no more objects in the collection, .Dv NULL is returned. t Fn prop_object_iterator_reset "prop_object_iterator_t iter" Reset the iterator to the first object in the collection being iterated by the iterator .Fa iter . t Fn prop_object_iterator_release "prop_object_iterator_t iter" Release the iterator .Fa iter . t Fn prop_object_externalize "prop_object_t obj" Externalizes an object, returning a NUL-terminated buffer containing a representation of the object in the default format
q XML property list . The caller is responsible for freeing the returned buffer. If converting to the external representation fails for any reason, .Dv NULL is returned.
p In user space, the buffer is allocated using .Xr malloc 3 . In the kernel, the buffer is allocated using .Xr malloc 9 using the malloc type .Dv M_TEMP . t Fn prop_object_externalize_with_format "prop_object_t obj" \ "prop_format_t format" Like .Fn prop_object_externalize , except the output format is specified explicitly. The following formats are supported:
p l -tag -width "PROP_FORMAT_JSON" -compact t Dv PROP_FORMAT_JSON RFC 8259 JSON format t Dv PROP_FORMAT_XML XML property list format .El t Fn prop_object_externalize_to_file "prop_object_t" \ "const char *path" t Fn prop_object_externalize_to_file_with_format "prop_object_t" \ "const char *path" "prop_format_t format" Like .Fn prop_object_externalize and .Fn prop_object_externalize_with_format , except the external representation is written to the file specified by .Fa path . The file is saved with the mode .Dv 0666 as modified by the process's file creation mask
q see Xr umask 2 and is written atomically. Returns .Dv false if externalizing the object or writing the file fails for any reason. t Fn prop_object_internalize "const char *data" Parses the external representation of an object in the NUL-terminated buffer .Fa data and returns the corresponding object. The format of the external representation is detected automatically. Returns .Dv NULL if parsing fails for any reason. t Fn prop_object_internalize_from_file "const char *path" .El .Sh SEE ALSO .Xr prop_array 3 , .Xr prop_bool 3 , .Xr prop_data 3 , .Xr prop_dictionary 3 , .Xr prop_number 3 , .Xr prop_string 3 , .Xr proplib 3 .Sh HISTORY The .Xr proplib 3 property container object library first appeared in .Nx 4.0 .