comparison 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
comparison
equal deleted inserted replaced
743:e2873f764b63 744:4181d43f91f9
435 * which will be automatically freed (if necessary) and replaced with 435 * which will be automatically freed (if necessary) and replaced with
436 * a pointer to the newly created string. 436 * a pointer to the newly created string.
437 * @param[in,out] buf pointer to a char pointer/string 437 * @param[in,out] buf pointer to a char pointer/string
438 * @param[in] fmt format string 438 * @param[in] fmt format string
439 * @param[in] args variable arguments list structure 439 * @param[in] args variable arguments list structure
440 */ 440 * @returns the resulting string or @c NULL pointer in case of error
441 void th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap) 441 */
442 th_char_t *th_pstr_vprintf(th_char_t **buf, const th_char_t *fmt, va_list ap)
442 { 443 {
443 th_char_t *tmp = th_strdup_vprintf(fmt, ap); 444 th_char_t *tmp = th_strdup_vprintf(fmt, ap);
444 th_free(*buf); 445 th_free(*buf);
445 *buf = tmp; 446 *buf = tmp;
447 return tmp;
446 } 448 }
447 449
448 450
449 /** 451 /**
450 * A helper function that is given a pointer to a pointer of string, 452 * A helper function that is given a pointer to a pointer of string,
451 * which will be automatically freed (if necessary) and replaced with 453 * which will be automatically freed (if necessary) and replaced with
452 * a pointer to the newly created string. 454 * a pointer to the newly created string.
453 * @param[in,out] buf pointer to a char pointer/string 455 * @param[in,out] buf pointer to a char pointer/string
454 * @param[in] fmt format string 456 * @param[in] fmt format string
455 * @param[in] ... optional printf arguments 457 * @param[in] ... optional printf arguments
456 */ 458 * @returns the resulting string or @c NULL pointer in case of error
457 void th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...) 459 */
460 th_char_t *th_pstr_printf(th_char_t **buf, const th_char_t *fmt, ...)
458 { 461 {
459 th_char_t *tmp; 462 th_char_t *tmp;
460 va_list ap; 463 va_list ap;
461 464
462 va_start(ap, fmt); 465 va_start(ap, fmt);
463 tmp = th_strdup_vprintf(fmt, ap); 466 tmp = th_strdup_vprintf(fmt, ap);
464 va_end(ap); 467 va_end(ap);
465 468
466 th_free(*buf); 469 th_free(*buf);
467 *buf = tmp; 470 *buf = tmp;
471 return tmp;
468 } 472 }
469 473
470 474
471 /* Compare two strings ignoring case [strcasecmp, strncasecmp] 475 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
472 */ 476 */