nbdkit_strdup_intern(3)
π nbdkit_strdup_intern(3) β the intern girlies π
okay so bestie, welcome to nbdkit_strdup_intern, section 3 of the manual, brought to you by the NBDKIT girlies. this page is about four little functions that make strings that live exactly as long as they're supposed to and then β¨peace outβ¨. no leaks, no drama, no bookkeeping situationship.
β¨ NAME β¨
nbdkit_strdup_intern, nbdkit_strndup_intern, nbdkit_printf_intern, nbdkit_vprintf_intern β create a string with limited lifetime for nbdkit π
πΈ SYNOPSIS πΈ
#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);
like, that's it. four functions. iconic lineup fr fr π
π¦ DESCRIPTION π¦
so here's the tea, bestie. some callbacks are specified to return const char *, even when a plugin may not have a suitable compile-time constant just chillin' there to return. and if you return dynamically-allocated memory for a callback like that? memory leak π or worse, you end up making the plugin do a whole bunch of extra bookkeeping and it's giving... chaos.
for these cases, nbdkit provides several convenience functions for creating a copy of a string, so your lifetime management is actually, y'know, managed. periodt.
π 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. lowkey the cleanest glow-up ever.
now pay attention because this part matters π
- If the copy is created outside the scope of a connection (such as during
.loador.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
.preconnector.open), the lifetime will last at least through.close, but the copy is not safe to share with other connections. nope. don't do it. that's a vibe check fail.
π 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. so like, the lazy girl's path to the exact same result. we love efficiency. π«Ά
β RETURN VALUE β
These functions return a string. This returned string must not be freed by the caller. It will be freed by nbdkit. so hands off bestie, it's not yours π€
If there is an error they call nbdkit_error(3) and return -1. yeah. that's the whole sentence. just so you know.
π HISTORY π
The intern functions were added in nbdkit 1.24. vintage but make it forever relevant π
π SEE ALSO π
go read them, i'll wait πΈ
π« AUTHORS π«
Eric Blake β shoutout to the author, absolute legend, no cap π
π COPYRIGHT π
Copyright Red Hat
π§ LICENSE π§
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY RED HAT 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 RED HAT 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.
like, all caps legal text but make it a warning, because it is one. read it fr fr π
okay that's the whole page, you ate that π this was nbdkit-1.48.1, dated 2026-08-29, and it's the nbdkit_strdup_intern(3) manual page. love u, bye π«Άβ¨
π¦ where this page comes from
- fedora 44: nbdkit-devel 1.48.1-1.fc44 Β· BSD-3-Clause
- fedora 44: nbdkit-devel 1.48.1-1.fc44 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms