talloc_string(3)

๐Ÿ“ฆ
version 2.4.4 ยท 3 versions
, in centos-stream 10, fedora 43, opensuse-leap 16.0

๐ŸŽ€ talloc_string(3) ๐ŸŽ€

okay so this page comes from the Library Functions Manual, and it's literally the talloc_string page. Bestie, it's all about the talloc string functions โ€” allocation and manipulation, the whole vibe. ๐Ÿ’…

โœจ NAME โœจ

talloc_string โ€” The talloc string functions.

  • talloc string allocation and manipulation functions. ๐Ÿซถ

๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

Here's the map, bestie โ€” topics and functions, no cap:

๐ŸŽ€ Topics ๐ŸŽ€

๐Ÿงš The talloc debugging support functions ๐Ÿงš

To aid memory debugging, talloc contains routines to inspect the currently allocated memory hierarchy. That's the debug-support corner of the talloc universe. ๐Ÿ”ฅ

๐Ÿ’– Functions ๐Ÿ’–

The full function roster is giving organized main character energy โ€” every signature stays exactly as it is:

  • _PUBLIC_ char * talloc_strdup (const void *t, const char *p) โ€” Duplicate a string into a talloc chunk. โœจ
  • _PUBLIC_ char * talloc_strdup_append (char *s, const char *a) โ€” Append a string to given string. ๐Ÿ’…
  • _PUBLIC_ char * talloc_strdup_append_buffer (char *s, const char *a) โ€” Append a string to a given buffer. ๐Ÿซถ
  • _PUBLIC_ char * talloc_strndup (const void *t, const char *p, size_t n) โ€” Duplicate a length-limited string into a talloc chunk. ๐ŸŽ€
  • _PUBLIC_ char * talloc_strndup_append (char *s, const char *a, size_t n) โ€” Append at most n characters of a string to given string. ๐ŸŒธ
  • _PUBLIC_ char * talloc_strndup_append_buffer (char *s, const char *a, size_t n) โ€” Append at most n characters of a string to given buffer. ๐Ÿฆ‹
  • _PUBLIC_ char * talloc_vasprintf (const void *t, const char *fmt, va_list ap) โ€” Format a string given a va_list. โญ
  • _PUBLIC_ char * talloc_vasprintf_append (char *s, const char *fmt, va_list ap) โ€” Format a string given a va_list and append it to the given destination string. ๐Ÿ’–
  • _PUBLIC_ char * talloc_vasprintf_append_buffer (char *s, const char *fmt, va_list ap) โ€” Format a string given a va_list and append it to the given destination buffer. ๐ŸŒˆ
  • _PUBLIC_ void talloc_asprintf_addbuf (char **ps, const char *fmt,...) โ€” Build up a string buffer, handle allocation failure. Responsible icon behavior. ๐Ÿ‘‘
  • _PUBLIC_ char * talloc_asprintf (const void *t, const char *fmt,...) โ€” Format a string. Periodt. ๐Ÿ”ฅ
  • _PUBLIC_ char * talloc_asprintf_append (char *s, const char *fmt,...) โ€” Append a formatted string to another string. ๐Ÿ’œ
  • _PUBLIC_ char * talloc_asprintf_append_buffer (char *s, const char *fmt,...) โ€” Append a formatted string to another string. ๐Ÿ“

๐Ÿ’œ Detailed Description ๐Ÿ’œ

talloc string allocation and manipulation functions. That's the whole summary โ€” talloc string allocation and manipulation functions, literally. ๐Ÿฆ‹

โœจ talloc_asprintf() โœจ

_PUBLIC_ char * talloc_asprintf (const void * t, const char * fmt,  ...)

Format a string, bestie โ€” this is literally the talloc glow-up of the C library's asprintf(3). ๐Ÿ’…

Okay so it also sets the name of the new pointer to the new string. Like, exactly equivalent to:

talloc_set_name_const(ptr, ptr)

Parameters

  • t โ€” the talloc context you're hanging the result off of ๐ŸŽ€
  • fmt โ€” the format string
  • ... โ€” the parameters used to fill fmt

Returns

The formatted string, or NULL on error. ๐Ÿ˜ญ


โœจ talloc_asprintf_addbuf() โœจ

_PUBLIC_ void talloc_asprintf_addbuf (char ** ps, const char * fmt,  ...)

Build up a string buffer โ€” and handle allocation failure while you're at it. Iconic behaviour tbh. โœจ

Parameters

  • ps โ€” pointer to the talloc'ed string you wanna extend
  • fmt โ€” the format string
  • ... โ€” the parameters used to fill fmt

Here's the slay part: this does nothing if *ps is NULL, and it sets *ps to NULL if the intermediate reallocation fails. So it's genuinely useful when you're building up a string step by step โ€” no intermediate NULL checks required. Periodt. ๐Ÿ’…


โœจ talloc_asprintf_append() โœจ

_PUBLIC_ char * talloc_asprintf_append (char * s, const char * fmt,  ...)

Appends a formatted string to another string, fr fr. Use this variant when the string in the current talloc buffer may have been truncated in length โ€” that's the whole vibe check on this one. ๐Ÿฆ‹

It sets the name of the new pointer to the new string, equivalent to:

talloc_set_name_const(ptr, ptr)

And if s == NULL, a whole new context gets created. ๐Ÿ‘‘

Parameters

  • s โ€” the string to append to
  • fmt โ€” the format string
  • ... โ€” the parameters used to fill fmt

Returns

The formatted string, or NULL on error.


โœจ talloc_asprintf_append_buffer() โœจ

_PUBLIC_ char * talloc_asprintf_append_buffer (char * s, const char * fmt,
    ...)

Appends a formatted string to another string, but this is the more efficient version of talloc_asprintf_append(). It figures out the length of the destination string from the size of the talloc context instead of from the string itself. Efficiency ate, ngl. ๐Ÿ”ฅ

โš ๏ธ Use this very carefully โ€” it produces a different result than talloc_asprintf_append() when there's a zero character in the middle of the destination string. Like, not a cute difference. Pay attention. ๐Ÿ’€

Check it:

char *str_a = talloc_strdup(NULL, "hello world");
char *str_b = talloc_strdup(NULL, "hello world");
str_a[5] = str_b[5] = '\0'

char *app = talloc_asprintf_append(str_a, "%s", ", hello");
char *buf = talloc_strdup_append_buffer(str_b, "%s", ", hello");

printf("%s\n", app); // hello, hello (app = "hello, hello")
printf("%s\n", buf); // hello (buf = "hello\0world, hello")

See how they diverge?? buf keeps the whole buffer including the stuff after the \0. ๐Ÿ™ˆ

If s == NULL then a new context is created.

Parameters

  • s โ€” the string to append to
  • fmt โ€” the format string
  • ... โ€” the parameters used to fill fmt

Returns

The formatted string, or NULL on error.

See also

  • talloc_asprintf()
  • talloc_asprintf_append()

โœจ talloc_strdup() โœจ

_PUBLIC_ char * talloc_strdup (const void * t, const char * p)

Duplicates a string into a talloc chunk. It's equivalent to:

ptr = talloc_size(ctx, strlen(p)+1);
if (ptr) memcpy(ptr, p, strlen(p)+1);

It sets the name of the new pointer to the string you passed in, equivalent to:

talloc_set_name_const(ptr, ptr)

Parameters

  • t โ€” the talloc context to hang the result off of
  • p โ€” the string you wanna duplicate ๐ŸŒธ

Returns

The duplicated string, or NULL on error.


โœจ talloc_strdup_append() โœจ

_PUBLIC_ char * talloc_strdup_append (char * s, const char * a)

Appends a string to a given string. The destination string gets reallocated to take strlen(s) + strlen(a) + 1 characters. Math, but make it cute. ๐Ÿงฎโœจ

It sets the name of the new pointer to the new string, equivalent to:

talloc_set_name_const(ptr, ptr)

If s == NULL then a new context is created.

Parameters

  • s โ€” the destination to append to
  • a โ€” the string you wanna append

Returns

The concatenated strings, or NULL on error.

See also

  • talloc_strdup()
  • talloc_strdup_append_buffer()

โœจ talloc_strdup_append_buffer() โœจ

_PUBLIC_ char * talloc_strdup_append_buffer (char * s, const char * a)

Appends a string to a given buffer โ€” the more efficient version of talloc_strdup_append(). It determines the length of the destination string by the size of the talloc context. ๐Ÿฆ‹

โš ๏ธ Again: use this very carefully. It produces a different result than talloc_strdup_append() when there's a zero character in the middle of the destination string. Bestie I'm serious. ๐Ÿ’€
char *str_a = talloc_strdup(NULL, "hello world");
char *str_b = talloc_strdup(NULL, "hello world");
str_a[5] = str_b[5] = '\0'

char *app = talloc_strdup_append(str_a, ", hello");
char *buf = talloc_strdup_append_buffer(str_b, ", hello");

printf("%s\n", app); // hello, hello (app = "hello, hello")
printf("%s\n", buf); // hello (buf = "hello\0world, hello")

If s == NULL then a new context is created.

Parameters

  • s โ€” the destination buffer to append to
  • a โ€” the string you wanna append

Returns

The concatenated strings, or NULL on error.

See also

  • talloc_strdup()
  • talloc_strdup_append()
  • talloc_array_length()

โœจ talloc_strndup() โœจ

_PUBLIC_ char * talloc_strndup (const void * t, const char * p, size_t n)

Duplicates a length-limited string into a talloc chunk. This is the talloc equivalent of the C library's strndup(3). ๐ŸŽ€

It sets the name of the new pointer to the string you passed in, equivalent to:

talloc_set_name_const(ptr, ptr)

Parameters

  • t โ€” the talloc context to hang the result off of
  • p โ€” the string you wanna duplicate
  • n โ€” the maximum string length to duplicate

Returns

The duplicated string, or NULL on error.


โœจ talloc_strndup_append() โœจ

_PUBLIC_ char * talloc_strndup_append (char * s, const char * a, size_t n)

Appends at most n characters of a string to a given string. The destination string gets reallocated to take strlen(s) + strnlen(a, n) + 1 characters. ๐ŸŒธ

It sets the name of the new pointer to the new string, equivalent to:

talloc_set_name_const(ptr, ptr)

If s == NULL then a new context is created.

Parameters

  • s โ€” the destination string to append to
  • a โ€” the source string you wanna append
  • n โ€” the number of characters you wanna append from the string

Returns

The concatenated strings, or NULL on error.

See also

  • talloc_strndup()
  • talloc_strndup_append_buffer()

โœจ talloc_strndup_append_buffer() โœจ

_PUBLIC_ char * talloc_strndup_append_buffer (char * s, const char * a,
    size_t n)

Appends at most n characters of a string to a given buffer โ€” the more efficient version of talloc_strndup_append(). It determines the length of the destination string by the size of the talloc context. ๐Ÿ”ฅ

โš ๏ธ Careful, careful, careful: it produces a different result than talloc_strndup_append() when a zero character sits in the middle of the destination string. ๐Ÿ’€
char *str_a = talloc_strdup(NULL, "hello world");
char *str_b = talloc_strdup(NULL, "hello world");
str_a[5] = str_b[5] = '\0'

char *app = talloc_strndup_append(str_a, ", hello", 7);
char *buf = talloc_strndup_append_buffer(str_b, ", hello", 7);

printf("%s\n", app); // hello, hello (app = "hello, hello")
printf("%s\n", buf); // hello (buf = "hello\0world, hello")

If s == NULL then a new context is created.

Parameters

  • s โ€” the destination buffer to append to
  • a โ€” the source string you wanna append
  • n โ€” the number of characters you wanna append from the string

Returns

The concatenated strings, or NULL on error.

See also

  • talloc_strndup()
  • talloc_strndup_append()
  • talloc_array_length()

โœจ talloc_vasprintf() โœจ

_PUBLIC_ char * talloc_vasprintf (const void * t, const char * fmt, va_list
    ap)

Formats a string given a va_list. This one's the talloc equivalent of the C library's vasprintf(3). ๐Ÿ‘‘

It sets the name of the new pointer to the new string, equivalent to:

talloc_set_name_const(ptr, ptr)

Parameters

  • t โ€” the talloc context to hang the result off of
  • fmt โ€” the format string
  • ap โ€” the parameters used to fill fmt

Returns

The formatted string, or NULL on error.


โœจ talloc_vasprintf_append() โœจ

_PUBLIC_ char * talloc_vasprintf_append (char * s, const char * fmt, va_list
    ap)

Formats a string given a va_list and appends it to the given destination string. ๐Ÿซถ

Parameters

  • s โ€” the destination string to append to
  • fmt โ€” the format string
  • ap โ€” the parameters used to fill fmt

Returns

The formatted string, or NULL on error.

See also

  • talloc_vasprintf()

Format a string given a va_list and append it to the given destination string.

Good for gradually accumulating output into a string buffer. Appends at the end of the string. โœจ


โœจ talloc_vasprintf_append_buffer() โœจ

_PUBLIC_ char * talloc_vasprintf_append_buffer (char * s, const char * fmt,
    va_list ap)

Formats a string given a va_list and appends it to the given destination buffer. ๐Ÿ’œ

Parameters

  • s โ€” the destination buffer to append to
  • fmt โ€” the format string
  • ap โ€” the parameters used to fill fmt

Returns

The formatted string, or NULL on error.

See also

  • talloc_vasprintf()

Format a string given a va_list and append it to the given destination buffer.

Always appends at the end of the talloc'ed buffer, not the end of the string. ๐ŸŽ€ (Yes, that distinction is the whole plot. It matters.)


๐ŸŒˆ AUTHOR ๐ŸŒˆ

Generated automatically by Doxygen for talloc from the source code. Not even a human handwriting this, it's giving robot-birth. ๐Ÿค–โœจ


Okay bestie, that's the whole page ๐Ÿ’– this was talloc_string(3), from talloc Version 2.0, and it's been a journey. Go forth and string-duplicate responsibly ๐Ÿซถ๐ŸŽ€๐Ÿ˜ญ