changeset 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 e2873f764b63
children 0c90dd46c49f
files th_string.c th_string.h
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
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;
 }
 
 
--- a/th_string.h	Wed Dec 14 01:38:31 2022 +0200
+++ b/th_string.h	Wed Dec 14 22:58:12 2022 +0200
@@ -164,8 +164,8 @@
 th_char_t   *th_strdup_printf(const th_char_t *fmt, ...)
             TH_ATTR_PRINTF_FMT(1, 2);
 
-void        th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap);
-void        th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...)
+th_char_t  *th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap);
+th_char_t  *th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...)
             TH_ATTR_PRINTF_FMT(2, 3);
 
 int         th_pstr_cpy(th_char_t **pdst, const th_char_t *src);