# HG changeset patch # User Matti Hamalainen # Date 1671051492 -7200 # Node ID 4181d43f91f9fa094a8770378fa92dc0d2bb9649 # Parent e2873f764b63b02a50002de5ee45ac8675f17d8a Change th_pstr_printf()/th_pstr_vprintf() to return pointer to the newly allocated string buffer, instead of void. diff -r e2873f764b63 -r 4181d43f91f9 th_string.c --- 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; } diff -r e2873f764b63 -r 4181d43f91f9 th_string.h --- 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);