Creating adr_name_t
Type
ADR names are composed of a domain and a set of key/value pairs. Two functions are provided that take exactly those arguments and return an adr_name_t
:
adr_name_t *adr_name_create(const char *domain, int count,
const char * const *keys, const char * const *values);
adr_name_t *adr_name_vcreate
(const char *domain, int count, ...);
Both forms take a domain argument, which should be a reverse-dotted domain name, and the number of key/value pairs as count. The two differ in how the key/value values are communicated. In the first form, adr_name_create, two char
* arrays are provided, one for keys and the other for values, as shown in the following example.
Example 3-3 Creating Names With adr_name_create
const char *keys[] = { "key1", "key2" }; const char *values[] = { "value1", "value2" }; name = adr_name_create("com.example", 2, keys, values);
In the second form, adr_name_vcreate, keys and values are provided as alternating varargs. The previous example written using adr_name_vcreate would look like the following example.
Example 3-4 Creating Names With adr_name_vcreate
name = adr_name_vcreate("com.example", 2, "key1", "value1", "key2", "value2");
If either routine fails to create the adr_name_t
, it will return NULL
. All data provided to adr_name_create is copied and can subsequently be modified or freed without affecting existing adr_name_t
types.