Skip site navigation (1)Skip section navigation (2)

  
 
  

home | help
nbdkit_strdup_intern(3) 	     NBDKIT		 nbdkit_strdup_intern(3)

NAME
     nbdkit_strdup_intern, nbdkit_strndup_intern, nbdkit_printf_intern, nbd-
     kit_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);

DESCRIPTION
     Some callbacks are specified to return "const char *", even when a plugin
     may not have a suitable compile-time constant to return.  Returning dynami-
     cally-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 as-
     printf(3) on a temporary string, then passing that result to "nbd-
     kit_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.

HISTORY
     The intern functions were added in nbdkit 1.24.

SEE ALSO
     nbdkit(1), nbdkit-plugin(3), nbdkit-filter(3).

AUTHORS
     Eric Blake

COPYRIGHT
     Copyright Red Hat

LICENSE
     Redistribution and use in source and binary forms, with or without modifi-
     cation, 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 no-
	 tice, this list of conditions and the following disclaimer in the docu-
	 mentation 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 EX-
     PRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
     CLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DI-
     RECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SER-
     VICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABIL-
     ITY, 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 DAM-
     AGE.

nbdkit-1.46.2			   2026-08-30		 nbdkit_strdup_intern(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=nbdkit_vprintf_intern&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help