nbdkit_printf_intern3
Create a string with limited lifetime for nbdkit
Part of nbdkit_strdup_intern(3).
Usage
#include <nbdkit-plugin.h>const char *nbdkit_strdup_intern (const char *str);const char *nbdkit_strndup_intern (const char *str, size_t n);const char *nbdkit_printf_intern (const char *fmt, ...);const char *nbdkit_vprintf_intern (const char *fmt, va_list ap);
Overview
Some callbacks are specified to return "const char *", even when a plugin may not have a suitable compile-time constant to return. Returning dynamically-allocated memory for such a callback would induce a memory leak or otherwise complicate the plugin to perform additional bookkeeping. For these cases, nbdkit provides several convenience functions for creating a copy of a string for better lifetime management.
nbdkit_strdup_intern
nbdkit_strndup_intern
Returns a copy of "str", possibly limited to a maximum of "n" bytes. After calling this, the plugin may free "str" and use this copy in its place.
If the copy is created outside the scope of a connection (such as during ".load" or ".config"), the lifetime of the copy will last at least through ".unload".
If the copy is created after a client has triggered a connection (such as during ".preconnect" or ".open"), the lifetime will last at least through ".close", but the copy is not safe to share with other connections.
"nbdkit_printf_intern"
"nbdkit_vprintf_intern"
Return a string created from a format template, with a lifetime longer than the current connection. These are shorthand for passing "fmt" to asprintf(3) on a temporary string, then passing that result to "nbdkit_strdup_intern".
Return value
These functions return a string. This returned string must not be freed by the caller. It will be freed by nbdkit.
If there is an error they call nbdkit_error(3) and return -1.