changeset 30:10d2dc143e4b

Add helper functions th_pstr_vprintf() and th_pstr_printf().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 11 Jun 2011 05:04:39 +0300
parents 04cfdefc3253
children a3ad77382c64
files th_string.c th_string.h
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Sat Jun 11 05:03:58 2011 +0300
+++ b/th_string.c	Sat Jun 11 05:04:39 2011 +0300
@@ -96,6 +96,27 @@
 }
 
 
+void th_pstr_vprintf(char **buf, const char *fmt, va_list ap)
+{
+    char *tmp = th_strdup_vprintf(fmt, ap);
+    th_free(*buf);
+    *buf = tmp;
+}
+
+
+void th_pstr_printf(char **buf, const char *fmt, ...)
+{
+    char *tmp;
+    va_list ap;
+
+    va_start(ap, fmt);
+    tmp = th_strdup_vprintf(fmt, ap);
+    va_end(ap);
+
+    th_free(*buf);
+    *buf = tmp;
+}
+
 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
  */
 int th_strcasecmp(const char * str1, const char * str2)
--- a/th_string.h	Sat Jun 11 05:03:58 2011 +0300
+++ b/th_string.h	Sat Jun 11 05:04:39 2011 +0300
@@ -50,6 +50,9 @@
 char    *th_strdup_vprintf(const char *, va_list);
 char    *th_strdup_printf(const char *, ...);
 
+void    th_pstr_vprintf(char **, const char *, va_list);
+void    th_pstr_printf(char **, const char *, ...);
+
 char    *th_strdup(const char *);
 int     th_pstrcpy(char **, const char *);
 int     th_pstrcat(char **, const char *);