summaryrefslogtreecommitdiff
path: root/common/lib/libprop/prop_string.3
blob: d2a1117a4cd39249cd3611159e1c486a401c46fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.\"	$NetBSD: prop_string.3,v 1.10 2020/06/06 21:25:59 thorpej Exp $
.\"
.\" Copyright (c) 2006, 2020 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 June 2, 2020
.Dt PROP_STRING 3
.Os
.Sh NAME
.Nm prop_string ,
.Nm prop_string_create_copy ,
.Nm prop_string_create_format ,
.Nm prop_string_create_nocopy ,
.Nm prop_string_value ,
.Nm prop_string_copy_value ,
.Nm prop_string_copy ,
.Nm prop_string_size ,
.Nm prop_string_equals ,
.Nm prop_string_equals_string ,
.Nm prop_string_compare ,
.Nm prop_string_compare_string
.Nd string value property object
.Sh LIBRARY
.Lb libprop
.Sh SYNOPSIS
.In prop/proplib.h
.\"
.Ft prop_string_t
.Fn prop_string_create_copy "const char *cstring"
.Ft prop_string_t
.Fn prop_string_create_format "const char *fmt" "..."
.Ft prop_string_t
.Fn prop_string_create_nocopy "const char *cstring"
.\"
.Ft prop_string_t
.Fn prop_string_copy "prop_string_t string"
.Ft bool
.Fn prop_string_copy_value "prop_string_t string" "char *buf" "size_t buflen"
.\"
.Ft size_t
.Fn prop_string_size "prop_string_t string"
.\"
.Ft const char *
.Fn prop_string_value "prop_string_t string"
.\"
.Ft bool
.Fn prop_string_equals "prop_string_t str1" "prop_string_t str2"
.Ft bool
.Fn prop_string_equals_string "prop_string_t string" "const char *cstring"
.\"
.Ft int
.Fn prop_string_compare "prop_string_t str1" "prop_string_t str2"
.Ft int
.Fn prop_string_compare_string "prop_string_t string" "const char *cstring"
.Sh DESCRIPTION
The
.Nm
family of functions operate on a string value property object type.
.Bl -tag -width "xxxxx"
.It Fn prop_string_create_copy "const char *cstring"
Create a string object that contains a copy of
.Fa cstring .
Returns
.Dv NULL
on failure.
.It Fn prop_string_create_format "const char *fmt" "..."
Similar to
.Fn prop_string_create_copy ,
but creates the string using the specified
.Xr printf 3
format.
.It Fn prop_string_create_nocopy "const char *cstring"
Similar to
.Fn prop_string_create_copy ,
but is allowed to not create an internal copy of the string data, instead
referencing the string data passed by the caller.
Caution must be exercised because string objects can have an indefinite
lifespan.
The caller must therefore ensure that the provided string data
reference will also be valid indefinitely.
This is provided only as a memory optimization; it is not guaranteed that
the returned string object will reference the provided string data, and
thus callers should not rely on this behavior.
Returns
.Dv NULL
on failure.
.It Fn prop_string_copy "prop_string_t string"
Copy a string object.
If the string object being copied has an external string buffer reference,
then the copy also references the same external string buffer.
Returns
.Dv NULL
on failure.
.It Fn prop_string_size "prop_string_t string"
Returns the size of the string, not including the terminating NUL;
equivalent semantics to
.Xr strlen 3 .
If the supplied object isn't a string, zero is returned.
.It Fn prop_string_value "prop_string_t string"
Returns an reference to the contents of the string as a C string.
If the supplied object isn't a string,
.Dv NULL
is returned.
.It Fn prop_string_copy_value "prop_string_t string" "void *buf" "size_t buflen"
Copies the contents of the string object including the terminating NUL
into the supplied buffer of the specified size.
Returns
.Dv true
if the copy succeeds
and
.Dv false
if the supplied buffer is not large enough or if the object is not a
string object.
.It Fn prop_string_equals "prop_string_t str1" "prop_string_t str2"
Returns
.Dv true
if the two string objects are equivalent.
.It Fn prop_string_equals_string "prop_string_t string" "const char *cstring"
Returns
.Dv true
if the string's value is equivalent to
.Fa cstring .
.It Fn prop_string_compare "prop_string_t str1" "prop_string_t str2"
Compares two strings using
.Xr strcmp 3
semantics.
If either of the two objects are not string objects, an arbitrary
non-matching value will be returned.
.It Fn prop_string_compare_string "prop_string_t string" "const char *cstring"
Compares the a string object to the specified C string using
.Xr strcmp 3
semantics.
If either the object is not a string object, an arbitrary
non-matching value will be returned.
.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_object 3 ,
.Xr proplib 3
.Sh HISTORY
The
.Xr proplib 3
property container object library first appeared in
.Nx 4.0 .
Support for mutable string objects was deprecated in
.Nx 10.0 .