Talloc doc: talloc_asprintf_append_buffer()
authorPavel Březina <pbrezina@redhat.com>
Mon, 16 Apr 2012 11:32:02 +0000 (13:32 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 18 Apr 2012 08:27:16 +0000 (10:27 +0200)
Explains the difference between _append and _append_buffer.

lib/talloc/talloc.h

index 244785b3a4565b09838acb4f7882f69b5be42382..c1b56502669ebfb95ab1ab301d29423c8a892ab3 100644 (file)
@@ -1540,6 +1540,25 @@ char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3
 /**
  * @brief Append a formatted string to another string.
  *
+ * This is a more efficient version of talloc_asprintf_append(). It determines
+ * the length of the destination string by the size of the talloc context.
+ *
+ * Use this very carefully as it produces a different result than
+ * talloc_asprintf_append() when a zero character is in the middle of the
+ * destination string.
+ *
+ * @code
+ *      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")
+ * @endcode
+ *
  * @param[in]  s        The string to append to
  *
  * @param[in]  fmt      The format string.
@@ -1547,6 +1566,9 @@ char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3
  * @param[in]  ...      The parameters used to fill fmt.
  *
  * @return              The formatted string, NULL on error.
+ *
+ * @see talloc_asprintf()
+ * @see talloc_asprintf_append()
  */
 char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);