diff th_string.c @ 744:4181d43f91f9

Change th_pstr_printf()/th_pstr_vprintf() to return pointer to the newly allocated string buffer, instead of void.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 14 Dec 2022 22:58:12 +0200
parents 31bc1ed07cf5
children 600a3c08747f
line wrap: on
line diff
--- a/th_string.c	Wed Dec 14 01:38:31 2022 +0200
+++ b/th_string.c	Wed Dec 14 22:58:12 2022 +0200
@@ -437,12 +437,14 @@
  * @param[in,out] buf pointer to a char pointer/string
  * @param[in] fmt format string
  * @param[in] args variable arguments list structure
+ * @returns the resulting string or @c NULL pointer in case of error
  */
-void th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap)
+th_char_t *th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap)
 {
     th_char_t *tmp = th_strdup_vprintf(fmt, ap);
     th_free(*buf);
     *buf = tmp;
+    return tmp;
 }
 
 
@@ -453,8 +455,9 @@
  * @param[in,out] buf pointer to a char pointer/string
  * @param[in] fmt format string
  * @param[in] ... optional printf arguments
+ * @returns the resulting string or @c NULL pointer in case of error
  */
-void th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...)
+th_char_t *th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...)
 {
     th_char_t *tmp;
     va_list ap;
@@ -465,6 +468,7 @@
 
     th_free(*buf);
     *buf = tmp;
+    return tmp;
 }