common/utils: add tal_strdup_or_null helper.

It's not that uncommon to want to pass NULL through, for optional strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-22 16:42:57 +09:30
parent b6d347a6d3
commit 981d82c406
7 changed files with 22 additions and 34 deletions

View File

@@ -88,6 +88,9 @@ bool utf8_check(const void *buf, size_t buflen);
/* Check it's UTF-8, return copy (or same if TAKES), or NULL if not valid. */
char *utf8_str(const tal_t *ctx, const u8 *buf TAKES, size_t buflen);
/* Strdup, or pass through NULL */
char *tal_strdup_or_null(const tal_t *ctx, const char *str);
/* Use the POSIX C locale. */
void setup_locale(void);