strm_dict_set()

Updated: April 19, 2023

Add or modify a dictionary entry using strings

Synopsis:

#include <sys/strm.h>
strm_dict_t* strm_dict_set(strm_dict_t *dict,
                           const char *key,
                           const char *value)

Arguments:

dict
A dictionary handle.
key
The key of the entry to add or modify.
value
The new value of the entry.

Library:

libstrm

Description:

This function creates a new dictionary that is an exact replica of the one specified by dict, except that the entry specified by key is added or modified. The entry's value is set to value.

When the function succeeds, the original dictionary handle is destroyed and a handle to the new dictionary is returned.

If the original handle is the only one for that dictionary, the library can reuse the memory of the original dictionary in creating the new one. This means that if you build a dictionary by repeatedly calling strm_dict_set() and passing in the handle returned by the previous call, the library just keeps modifying the dictionary without having to make copies of the existing keys and values.

This same reusing of memory when there's only one handle to the dictionary is done by other functions that modify individual entries, such as strm_dict_set_index().

Returns:

A handle to the new dictionary on success, or a null pointer on failure.