[tor-commits] [tor/master] Add smartlist_[v]asprintf_add

nickm at torproject.org nickm at torproject.org
Wed Aug 10 19:06:43 UTC 2011


commit e42a74e56351a41c0a68999ed5fce48ab03166d7
Author: Robert Ransom <rransom.8774 at gmail.com>
Date:   Wed Aug 3 15:49:39 2011 -0700

    Add smartlist_[v]asprintf_add
    
    I should have added this before implementing #2411.
---
 src/common/util.c |   24 ++++++++++++++++++++++++
 src/common/util.h |    5 +++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 601f2be..1e5e454 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2679,6 +2679,30 @@ tor_sscanf(const char *buf, const char *pattern, ...)
   return r;
 }
 
+/** Append the string produced by tor_asprintf(<b>pattern</b>, <b>...</b>)
+ * to <b>sl</b>. */
+void
+smartlist_asprintf_add(struct smartlist_t *sl, const char *pattern, ...)
+{
+  va_list ap;
+  va_start(ap, pattern);
+  smartlist_vasprintf_add(sl, pattern, ap);
+  va_end(ap);
+}
+
+/** va_list-based backend of smartlist_asprintf_add. */
+void
+smartlist_vasprintf_add(struct smartlist_t *sl, const char *pattern,
+                        va_list args)
+{
+  char *str = NULL;
+
+  tor_vasprintf(&str, pattern, args);
+  tor_assert(str != NULL);
+
+  smartlist_add(sl, str);
+}
+
 /** Return a new list containing the filenames in the directory <b>dirname</b>.
  * Return NULL on error or if <b>dirname</b> is not a directory.
  */
diff --git a/src/common/util.h b/src/common/util.h
index 9935587..a1def6c 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -220,6 +220,11 @@ int tor_sscanf(const char *buf, const char *pattern, ...)
 #endif
   ;
 
+void smartlist_asprintf_add(struct smartlist_t *sl, const char *pattern, ...)
+  CHECK_PRINTF(2, 3);
+void smartlist_vasprintf_add(struct smartlist_t *sl, const char *pattern,
+                             va_list args);
+
 int hex_decode_digit(char c);
 void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen);
 int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen);





More information about the tor-commits mailing list