Talloc doc: talloc_strndup_append_buffer()
authorPavel Březina <pbrezina@redhat.com>
Mon, 16 Apr 2012 11:17:59 +0000 (13:17 +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 a77740f669b410de53eaa9feeb6053cdc43a63af..244785b3a4565b09838acb4f7882f69b5be42382 100644 (file)
@@ -1400,8 +1400,26 @@ char *talloc_strndup(const void *t, const char *p, size_t n);
 char *talloc_strndup_append(char *s, const char *a, size_t n);
 
 /**
- * @brief Append at most n characters of a string to given buffer and duplicate
- *        the result.
+ * @brief Append at most n characters of a string to given buffer
+ *
+ * This is a more efficient version of talloc_strndup_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_strndup_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_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")
+ * @endcode
  *
  * @param[in]  s        The destination buffer to append to.
  *
@@ -1413,6 +1431,8 @@ char *talloc_strndup_append(char *s, const char *a, size_t n);
  * @return              The duplicated string, NULL on error.
  *
  * @see talloc_strndup()
+ * @see talloc_strndup_append()
+ * @see talloc_array_length()
  */
 char *talloc_strndup_append_buffer(char *s, const char *a, size_t n);